﻿Imports GisMapF
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.IO
Public Class frmGis_map

    Public m_manager As LayerManager
    Public Assistant As New Assistant
    Private m_ArrayTop(-1) As Point
    Private m_ArrGrid(-1) As SDSGridLineLayer
    Private covertLocation As New UTM.Cover
    Private GeoPoint As New UTM.GeoPoint
    Private UtmZone As Integer = 50
    'Private Sub cpS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cpS.Click
    '    m_manager.SetAllLayerNoEdditable()

    '    Dim cpLayer As ESPointLayer
    '    m_manager.GetLayer("cpoint", cpLayer)
    '    If cpLayer IsNot Nothing Then

    '        cpLayer.SetDrawEntity(True)
    '    End If

    'End Sub
    Public Sub New(ByVal strProjPath As String)


        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。
        m_manager = New LayerManager(AxMap1, strProjPath)

        AddHandler m_manager.AskForAddEntity, AddressOf Me.OnAskAdd
        AddHandler m_manager.AskForRemoveEntity, AddressOf Me.OnAskRemove
        AddHandler m_manager.EntitySelected, AddressOf Me.OnSelected
        AddHandler m_manager.mousePosChanged, AddressOf Me.OnMousePosChanged
        AddHandler m_manager.AskForMove, AddressOf Me.OnMouseTransfer
    End Sub
    Public Sub SetGrid(ByVal LBUtmX As Double, ByVal LBUtmY As Double _
                       , ByVal XCells As Integer, ByVal YCells As Integer _
                       , ByVal Xunit As Double, ByVal Yuint As Double)
        Assistant.SetGrid("grid", LBUtmX, LBUtmY, XCells, YCells, Xunit, Yuint)
        Assistant.SetAxis("axis", LBUtmX, LBUtmY, XCells, YCells, Xunit, Yuint)
    End Sub
    ''' <summary>
    ''' 加载 GIS 各层的方法 
    ''' </summary>
    ''' <param name="t">t = True 时加载各层，t = False 不加载</param>
    ''' <remarks></remarks>
    Public Sub CreateGis(ByVal t As Boolean)
        If t = True Then

            Me.m_manager.UnloadAllLayer() '删除所有图层
            Assistant.m_manager = Me.m_manager

            '网格()
            'Dim grd As New SDSGridLineLayer("grid")
            'm_manager.AddLayer(grd)
            'grd.LdescProperty = "主网格"
            ''网格样式
            'grd.LineColorProperty = Color.Gray
            'grd.LBPointXAProperty = -6000
            'grd.LBPointYAProperty = -6000
            'grd.XCellsProperty = 500
            'grd.YCellsProperty = 500
            'grd.XunitLProperty = 25
            'grd.YuintLProperty = 25
            '坐标轴
            Dim axis As New SDSAxisLayer("axis")
            m_manager.AddLayer(axis)

            axis.LdescProperty = "坐标轴"
            'axis.LBPointXAProperty = -6000
            'axis.LBPointYAProperty = -6000

            'axis.XCellsProperty = 500
            'axis.YCellsProperty = 500

            'axis.XunitLProperty = 25
            'axis.YuintLProperty = 25

            'axis.LBPointXProperty = -6000
            'axis.LBPointYProperty = -6000

            axis.ScaleLProperty = 5


            'Assistant.SetGrid("grid", -6000, -6000, 24, 24, 500, 500)
            'Assistant.SetAxis("axis", -6000, -6000, 24, 24, 500, 500)

            '建筑物
            Dim layer9 As New ESPolygonLayer("build", New PolyTool)
            layer9.LdescProperty = "建筑物"
            m_manager.AddLayer(layer9)
            '建筑物样式
            layer9.FilltypeProperty = Layer.FtkFillStipple.fsNone
            layer9.LineColorProperty = Color.DarkSlateGray
            layer9.LineWidthProperty = 0
            layer9.FillColorProperty = Color.DarkSlateGray
            
            '点源
            Dim cpLayer2 As New ESPointLayer("ppoint", New PointTool)
            cpLayer2.LdescProperty = "点源"
            m_manager.AddLayer(cpLayer2)
            '点源样式 
            cpLayer2.PointsizeProperty = 8
            cpLayer2.PointColorProperty = Color.Blue
            cpLayer2.PointtypeProperty = Layer.FtkPointType.ptCircle


            '体源
            Dim layer5 As New ESPolygonLayer("cube", New SquareTool)
            layer5.LdescProperty = "体源"
            m_manager.AddLayer(layer5)
            '体源样式
            layer5.FilltypeProperty = Layer.FtkFillStipple.fsNone
            layer5.LineColorProperty = Color.Blue
            layer5.LineWidthProperty = 2
            layer5.FillColorProperty = Color.Blue

            '矩形面源
            Dim layer7 As New ESPolygonLayer("rect", New RectangleTool)
            layer7.LdescProperty = "矩形面源"
            m_manager.AddLayer(layer7)
            '矩形面源样式
            layer7.FilltypeProperty = Layer.FtkFillStipple.fsNone
            layer7.LineColorProperty = Color.Blue
            layer7.LineWidthProperty = 2
            layer7.FillColorProperty = Color.Blue

            '多边形源
            Dim layer4 As New ESPolygonLayer("poly", New PolyTool)
            layer4.LdescProperty = "多边形源"
            m_manager.AddLayer(layer4)
            '多边形源样式l
            layer4.FilltypeProperty = Layer.FtkFillStipple.fsNone
            layer4.LineColorProperty = Color.Blue
            layer4.LineWidthProperty = 2
            layer4.FillColorProperty = Color.Blue

            '圆形面源
            Dim layer6 As New ESPolygonLayer("circle", New CirclePolyToolV3)
            layer6.LdescProperty = "圆形面源"
            m_manager.AddLayer(layer6)
            '圆形面源样式
            layer6.FilltypeProperty = Layer.FtkFillStipple.fsNone
            layer6.LineColorProperty = Color.Blue
            layer6.LineWidthProperty = 2
            layer6.FillColorProperty = Color.Blue

            '敞口源
            Dim layer8 As New ESPolygonLayer("exp", New RectangleTool)
            layer8.LdescProperty = "敞口源"
            m_manager.AddLayer(layer8)
            '敞口源样式 
            layer8.FilltypeProperty = Layer.FtkFillStipple.fsNone
            layer8.LineColorProperty = Color.Blue
            layer8.LineWidthProperty = 2
            layer8.FillColorProperty = Color.Blue

            '线源
            Dim layer3 As New ESMLineLayer("pline", New CPlineTool)
            layer3.LdescProperty = "线源"
            m_manager.AddLayer(layer3)
            '线源样式
            layer3.LineWidthProperty = 2
            layer3.LineColorProperty = Color.Blue


            ' 关心点 
            Dim cpLayer As New ESPointLayer("cpoint", New PointTool)
            cpLayer.LdescProperty = "关心点"
            m_manager.AddLayer(cpLayer)
            '关心点样式
            cpLayer.PointsizeProperty = 8
            cpLayer.PointColorProperty = Color.ForestGreen
            cpLayer.PointtypeProperty = Layer.FtkPointType.ptTriangleUp
            cpLayer.ShowTextProperty = True
          End If

    End Sub
    '''' <summary>
    '''' 移除
    '''' </summary>
    '''' <param name="ln"></param>
    '''' <param name="sn"></param>
    '''' <remarks></remarks>
    'Private Sub OnAskRemove(ByVal ln As String, ByVal sn As String)

    '    Dim cpLayer As EditableShapeLayer
    '    m_manager.GetLayer(ln, cpLayer)
    '    If cpLayer IsNot Nothing Then
    '        Select Case ln
    '            Case "ppoint", "pline", "pline", "poly", "cube", "circle", "rect", "exp"
    '                AermodProject0.Aermod.Source.RemoveFormID(sn)
    '            Case "cpoint" '关心点
    '                AermodProject0.Aermod.Receptor.RemoveDiscFormID(sn)
    '            Case "build" '建筑物
    '                AermodProject0.Aermod.Bprm.RemoveFormID(sn)
    '        End Select
    '        cpLayer.RemoveEntity(sn)
    '    End If
    '    Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
    '    myFrmMain.SolutionExplorer.RefreshSolutionTree()
    'End Sub
    ''' <summary>
    ''' 单个编辑
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SetBluepencil()
        Dim m_dic As Dictionary(Of String, String)
        m_dic = m_manager.GetSelectedShapeNamesWithLayerName()
        If m_dic.Count > 1 Then
            MsgBox("编辑时，只能选择一个！", MsgBoxStyle.OkOnly, "提示")
            Exit Sub
        ElseIf m_dic.Count = 0 Then
            MsgBox("请选择一个后再编辑！", MsgBoxStyle.OkOnly, "提示")
            Exit Sub
        End If
        For Each d As KeyValuePair(Of String, String) In m_dic

            Select Case d.Value
                Case "cpoint" '关心点
                    For j As Integer = 0 To AermodProject0.Aermod.Receptor.DiscCarts.Length - 1
                        If d.Key = AermodProject0.Aermod.Receptor.DiscCarts(j).ID Then
                            Dim dlgCare As New dlgSingleDiscCart
                            dlgCare.txtName.Text = AermodProject0.Aermod.Receptor.DiscCarts(j).Name
                            dlgCare.txtXcoord.Value = AermodProject0.Aermod.Receptor.DiscCarts(j).Xcoord
                            dlgCare.txtYcoord.Value = AermodProject0.Aermod.Receptor.DiscCarts(j).Ycoord
                            dlgCare.txtZelev.Value = AermodProject0.Aermod.Receptor.DiscCarts(j).Zelev
                            dlgCare.txtZhill.Value = AermodProject0.Aermod.Receptor.DiscCarts(j).Zhill
                            dlgCare.txtZflag.Value = AermodProject0.Aermod.Receptor.DiscCarts(j).Zflag
                            If dlgCare.ShowDialog = Windows.Forms.DialogResult.OK Then
                                AermodProject0.Aermod.Receptor.DiscCarts(j).Name = dlgCare.txtName.Text
                                AermodProject0.Aermod.Receptor.DiscCarts(j).Xcoord = dlgCare.txtXcoord.Value
                                AermodProject0.Aermod.Receptor.DiscCarts(j).Ycoord = dlgCare.txtYcoord.Value
                                AermodProject0.Aermod.Receptor.DiscCarts(j).Xcoord = FormatNumber(AermodProject0.Aermod.Receptor.DiscCarts(j).Xcoord, 0)
                                AermodProject0.Aermod.Receptor.DiscCarts(j).Ycoord = FormatNumber(AermodProject0.Aermod.Receptor.DiscCarts(j).Ycoord, 0)
                                AermodProject0.Aermod.Receptor.DiscCarts(j).Zelev = dlgCare.txtZelev.Value
                                AermodProject0.Aermod.Receptor.DiscCarts(j).Zhill = dlgCare.txtZhill.Value
                                AermodProject0.Aermod.Receptor.DiscCarts(j).Zflag = dlgCare.txtZflag.Value
                            End If
                        End If
                    Next

                Case "ppoint" '点源
                    For j As Integer = 0 To AermodProject0.Aermod.Source.PointSources.PointSource.Length - 1
                        If d.Key = AermodProject0.Aermod.Source.PointSources.PointSource(j).Location.Srcid Then
                            Dim dlgPoint As New dlgPointsSource
                            'dlgPoint.Modify()

                            Dim ps As New CAermod.PointSources
                            ps = AermodProject0.Aermod.Source.PointSources.Clone
                            dlgPoint.BaseSoruce = ps.PointSource
                            dlgPoint.Urbans = AermodProject0.Aermod.Control.Urbans.Clone
                            dlgPoint.IntialSelectedIndex = j
                            dlgPoint.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut.Clone  '所有选中的污染物
                            dlgPoint.Control = AermodProject0.Aermod.Control.Clone
                            dlgPoint.SourceCount = AermodProject0.Aermod.Source.PointSources.nStack
                            If dlgPoint.ShowDialog = Windows.Forms.DialogResult.OK Then
                                ps.PointSource = CType(dlgPoint.BaseSoruce, CAermod.PointSource())
                                AermodProject0.Aermod.Source.PointSources = ps
                                AermodProject0.Aermod.Source.PointSources.nStack = dlgPoint.SourceCount
                            End If

                        End If
                    Next
                Case "pline" '线源
                    For j As Integer = 0 To AermodProject0.Aermod.Source.LineSources.ArrayLineSources.Length - 1
                        If d.Key = AermodProject0.Aermod.Source.LineSources.ArrayLineSources(j).Location.Srcid Then
                            Dim dlgLine As New dlgLineSources
                            'dlgLine.Modify()
                            Dim ps As New CAermod.LineSources
                            ps = AermodProject0.Aermod.Source.LineSources.Clone
                            dlgLine.BaseSoruce = ps.ArrayLineSources
                            dlgLine.Urbans = AermodProject0.Aermod.Control.Urbans.Clone
                            dlgLine.IntialSelectedIndex = j
                            dlgLine.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut.Clone  '所有选中的污染物
                            dlgLine.Control = AermodProject0.Aermod.Control.Clone
                            dlgLine.SourceCount = AermodProject0.Aermod.Source.LineSources.nStack
                            If dlgLine.ShowDialog = Windows.Forms.DialogResult.OK Then
                                ps.ArrayLineSources = CType(dlgLine.BaseSoruce, CAermod.Line())
                                AermodProject0.Aermod.Source.LineSources = ps.Clone
                                AermodProject0.Aermod.Source.LineSources.nStack = dlgLine.SourceCount
                            End If
                        End If
                    Next
                Case "rect" '矩形面源 
                    For j As Integer = 0 To AermodProject0.Aermod.Source.AreaSources.AreaSource.Length - 1
                        If d.Key = AermodProject0.Aermod.Source.AreaSources.AreaSource(j).Location.Srcid Then
                            Dim dlgArea As New dlgAreaSource
                            'dlgArea.Modify()
                            Dim ps As New CAermod.AreaSources
                            ps = AermodProject0.Aermod.Source.AreaSources.Clone
                            dlgArea.BaseSoruce = ps.AreaSource
                            dlgArea.Urbans = AermodProject0.Aermod.Control.Urbans.Clone
                            dlgArea.IntialSelectedIndex = j
                            dlgArea.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut.Clone '所有选中的污染物
                            dlgArea.Control = AermodProject0.Aermod.Control.Clone
                            dlgArea.SourceCount = AermodProject0.Aermod.Source.AreaSources.nStack
                            If dlgArea.ShowDialog = Windows.Forms.DialogResult.OK Then
                                ps.AreaSource = CType(dlgArea.BaseSoruce, CAermod.AreaSource())
                                AermodProject0.Aermod.Source.AreaSources = ps
                                AermodProject0.Aermod.Source.AreaSources.nStack = dlgArea.SourceCount

                            End If

                        End If
                    Next
                Case "exp" '敞口源  
                    For j As Integer = 0 To AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource.Length - 1
                        If d.Key = AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(j).Location.Srcid Then
                            Dim dlgOpenPit As New dlgOpenPitSource
                            'dlgOpenPit.Modify()
                            Dim ps As New CAermod.OpenPitSources
                            ps = AermodProject0.Aermod.Source.OpenPitSources.Clone
                            dlgOpenPit.BaseSoruce = ps.OpenPitSource
                            dlgOpenPit.Urbans = AermodProject0.Aermod.Control.Urbans.Clone
                            dlgOpenPit.IntialSelectedIndex = j
                            dlgOpenPit.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut.Clone '所有选中的污染物
                            dlgOpenPit.Control = AermodProject0.Aermod.Control.Clone
                            dlgOpenPit.SourceCount = AermodProject0.Aermod.Source.OpenPitSources.nStack
                            If dlgOpenPit.ShowDialog = Windows.Forms.DialogResult.OK Then
                                ps.OpenPitSource = CType(dlgOpenPit.BaseSoruce, CAermod.OpenPitSource())
                                AermodProject0.Aermod.Source.OpenPitSources = ps.Clone
                                AermodProject0.Aermod.Source.OpenPitSources.nStack = dlgOpenPit.SourceCount
                            End If
                        End If
                    Next
                Case "circle" '圆形面源  
                    For j As Integer = 0 To AermodProject0.Aermod.Source.AreacircSources.AreaCircSource.Length - 1
                        If d.Key = AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(j).Location.Srcid Then
                            Dim dlgAreaCirc As New dlgAreaCircSource
                            'dlgAreaCirc.Modify() ‘小杨注释
                            Dim ps As New CAermod.AreaCircSources
                            ps = AermodProject0.Aermod.Source.AreacircSources.Clone
                            dlgAreaCirc.BaseSoruce = ps.AreaCircSource
                            dlgAreaCirc.Urbans = AermodProject0.Aermod.Control.Urbans.Clone
                            dlgAreaCirc.IntialSelectedIndex = j
                            dlgAreaCirc.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut.Clone  '所有选中的污染物
                            dlgAreaCirc.Control = AermodProject0.Aermod.Control.Clone
                            dlgAreaCirc.SourceCount = AermodProject0.Aermod.Source.AreacircSources.nStack
                            If dlgAreaCirc.ShowDialog = Windows.Forms.DialogResult.OK Then
                                ps.AreaCircSource = CType(dlgAreaCirc.BaseSoruce, CAermod.AreaCircSource())
                                AermodProject0.Aermod.Source.AreacircSources = ps.Clone
                                AermodProject0.Aermod.Source.AreacircSources.nStack = dlgAreaCirc.SourceCount
                            End If
                        End If
                    Next
                Case "cube" '体源   
                    For j As Integer = 0 To AermodProject0.Aermod.Source.VolumeSources.VolumeSource.Length - 1
                        If d.Key = AermodProject0.Aermod.Source.VolumeSources.VolumeSource(j).Location.Srcid Then
                            Dim dlgVolume As New dlgVolumeSource
                            'dlgVolume.Modify()
                            Dim ps As New CAermod.VolumeSources
                            ps = AermodProject0.Aermod.Source.VolumeSources.Clone
                            dlgVolume.BaseSoruce = ps.VolumeSource
                            dlgVolume.Urbans = AermodProject0.Aermod.Control.Urbans.Clone
                            dlgVolume.IntialSelectedIndex = j
                            dlgVolume.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut.Clone  '所有选中的污染物
                            dlgVolume.Control = AermodProject0.Aermod.Control.Clone
                            dlgVolume.SourceCount = AermodProject0.Aermod.Source.AreacircSources.nStack
                            If dlgVolume.ShowDialog = Windows.Forms.DialogResult.OK Then
                                ps.VolumeSource = CType(dlgVolume.BaseSoruce, CAermod.VolumeSource())
                                AermodProject0.Aermod.Source.VolumeSources = ps.Clone
                                AermodProject0.Aermod.Source.VolumeSources.nStack = dlgVolume.SourceCount

                            End If
                        End If
                    Next
                Case "poly" '多边形
                    For j As Integer = 0 To AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource.Length - 1
                        If d.Key = AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j).Location.Srcid Then
                            Dim dlgAreaPoly As New dlgAreaPolySource
                            'dlgAreaPoly.Modify()’小杨注释
                            Dim ps As New CAermod.AreaPolySources
                            ps = AermodProject0.Aermod.Source.AreaPolySources.Clone
                            dlgAreaPoly.BaseSoruce = ps.AreaPolySource
                            dlgAreaPoly.Urbans = AermodProject0.Aermod.Control.Urbans.Clone
                            dlgAreaPoly.IntialSelectedIndex = j
                            dlgAreaPoly.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut.Clone  '所有选中的污染物
                            dlgAreaPoly.Control = AermodProject0.Aermod.Control.Clone
                            dlgAreaPoly.SourceCount = AermodProject0.Aermod.Source.AreaPolySources.nStack
                            If dlgAreaPoly.ShowDialog = Windows.Forms.DialogResult.OK Then
                                ps.AreaPolySource = CType(dlgAreaPoly.BaseSoruce, CAermod.AreaPolySource())
                                AermodProject0.Aermod.Source.AreaPolySources = ps.Clone
                                AermodProject0.Aermod.Source.AreaPolySources.nStack = dlgAreaPoly.SourceCount

                            End If
                        End If
                    Next
                Case "build" '建筑物  
                    For j As Integer = 0 To AermodProject0.Aermod.Bprm.ArryBldgi.Length - 1
                        If d.Key = AermodProject0.Aermod.Bprm.ArryBldgi(j).BuildStack Then
                            Dim dlgBuilding As New CAermod.frmSingleBuilding

                            Dim ptA(AermodProject0.Aermod.Bprm.ArryBldgi(j).ArryBuildTire(0).ArryBuilCorner.Length - 1) As MapWinGIS.Point
                            For i As Integer = 0 To AermodProject0.Aermod.Bprm.ArryBldgi(j).ArryBuildTire(0).ArryBuilCorner.Length - 1
                                dlgBuilding.Bldgi = AermodProject0.Aermod.Bprm.ArryBldgi(j)
                            Next

                            If dlgBuilding.ShowDialog = Windows.Forms.DialogResult.OK Then
                                AermodProject0.Aermod.Bprm.ArryBldgi(j) = dlgBuilding.Bldgi
                            End If
                        End If
                    Next

            End Select
            Me.UpAllSource(d.Value)
        Next

    End Sub
    ''' <summary>
    ''' 移动
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub OnMouseTransfer(ByVal ln As String, ByVal sn As String(), ByVal myy As Double, ByVal mxx As Double)
        'Dim list_1 As New List(Of GisMapF.FEntity)
        'Dim m_dic As List(Of GisMapF.FEntity)
        'm_dic = m_manager.GetSelectedShapeNames()
        Select Case ln
            Case "cpoint" '移动关心点 
                For i As Integer = 0 To sn.Length - 1
                    For j As Integer = 0 To AermodProject0.Aermod.Receptor.DiscCarts.Length - 1
                        If sn(i) = AermodProject0.Aermod.Receptor.DiscCarts(j).ID Then
                            AermodProject0.Aermod.Receptor.DiscCarts(j).Xcoord += mxx
                            AermodProject0.Aermod.Receptor.DiscCarts(j).Ycoord += myy
                            AermodProject0.Aermod.Receptor.DiscCarts(j).Xcoord = FormatNumber(AermodProject0.Aermod.Receptor.DiscCarts(j).Xcoord, 0)
                            AermodProject0.Aermod.Receptor.DiscCarts(j).Ycoord = FormatNumber(AermodProject0.Aermod.Receptor.DiscCarts(j).Ycoord, 0)
                        End If
                    Next
                Next
            Case "ppoint" '点源
                For i As Integer = 0 To sn.Length - 1
                    For j As Integer = 0 To AermodProject0.Aermod.Source.PointSources.PointSource.Length - 1
                        If sn(i) = AermodProject0.Aermod.Source.PointSources.PointSource(j).Location.Srcid Then
                            AermodProject0.Aermod.Source.PointSources.PointSource(j).Location.Xs += mxx
                            AermodProject0.Aermod.Source.PointSources.PointSource(j).Location.Ys += myy
                            AermodProject0.Aermod.Source.PointSources.PointSource(j).Location.Xs = FormatNumber(AermodProject0.Aermod.Source.PointSources.PointSource(j).Location.Xs, 0)
                            AermodProject0.Aermod.Source.PointSources.PointSource(j).Location.Ys = FormatNumber(AermodProject0.Aermod.Source.PointSources.PointSource(j).Location.Ys, 0)

                        End If
                    Next
                Next
            Case "pline" '线源
                For i As Integer = 0 To sn.Length - 1
                    For j As Integer = 0 To AermodProject0.Aermod.Source.LineSources.ArrayLineSources.Length - 1

                        If sn(i) = AermodProject0.Aermod.Source.LineSources.ArrayLineSources(j).Location.Srcid Then
                            AermodProject0.Aermod.Source.LineSources.ArrayLineSources(j).Location.Xs += mxx
                            AermodProject0.Aermod.Source.LineSources.ArrayLineSources(j).Location.Ys += myy
                            For p As Integer = 0 To AermodProject0.Aermod.Source.LineSources.ArrayLineSources(j).LinePoints.Length - 1
                                AermodProject0.Aermod.Source.LineSources.ArrayLineSources(j).LinePoints(p).x += mxx
                                AermodProject0.Aermod.Source.LineSources.ArrayLineSources(j).LinePoints(p).y += myy
                                AermodProject0.Aermod.Source.LineSources.ArrayLineSources(j).LinePoints(p).x = FormatNumber(AermodProject0.Aermod.Source.LineSources.ArrayLineSources(j).LinePoints(p).x, 0)
                                AermodProject0.Aermod.Source.LineSources.ArrayLineSources(j).LinePoints(p).y = FormatNumber(AermodProject0.Aermod.Source.LineSources.ArrayLineSources(j).LinePoints(p).y, 0)

                            Next
                        End If
                    Next
                Next
            Case "poly" '多边形
                For i As Integer = 0 To sn.Length - 1
                    For j As Integer = 0 To AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource.Length - 1
                        If sn(i) = AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j).Location.Srcid Then
                            AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j).Location.Xs += mxx
                            AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j).Location.Ys += myy

                            For p As Integer = 0 To AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j).GetVerts.Length - 1
                                ReDim Preserve m_ArrayTop(p)
                                m_ArrayTop(p) = New Point
                                m_ArrayTop(p).X = AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j).GetVerts(p).X
                                m_ArrayTop(p).X += mxx
                                m_ArrayTop(p).Y = AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j).GetVerts(p).Y
                                m_ArrayTop(p).Y += myy
                                m_ArrayTop(p).X = FormatNumber(m_ArrayTop(p).X, 0)
                                m_ArrayTop(p).Y = FormatNumber(m_ArrayTop(p).Y, 0)
                            Next
                            AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j).SetVerts(m_ArrayTop)
                            AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j).Location.Xs = FormatNumber(AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j).Location.Xs, 0)
                            AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j).Location.Ys = FormatNumber(AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j).Location.Ys, 0)
                        End If

                    Next
                Next


            Case "cube" '体源  
                For i As Integer = 0 To sn.Length - 1
                    For j As Integer = 0 To AermodProject0.Aermod.Source.VolumeSources.VolumeSource.Length - 1
                        If sn(i) = AermodProject0.Aermod.Source.VolumeSources.VolumeSource(j).Location.Srcid Then
                            AermodProject0.Aermod.Source.VolumeSources.VolumeSource(j).Location.Xs += mxx
                            AermodProject0.Aermod.Source.VolumeSources.VolumeSource(j).Location.Ys += myy
                            AermodProject0.Aermod.Source.VolumeSources.VolumeSource(j).Location.Xs = FormatNumber(AermodProject0.Aermod.Source.VolumeSources.VolumeSource(j).Location.Xs, 0)
                            AermodProject0.Aermod.Source.VolumeSources.VolumeSource(j).Location.Ys = FormatNumber(AermodProject0.Aermod.Source.VolumeSources.VolumeSource(j).Location.Ys, 0)

                        End If
                    Next
                Next
            Case "circle" '圆形面源     
                For i As Integer = 0 To sn.Length - 1
                    For j As Integer = 0 To AermodProject0.Aermod.Source.AreacircSources.AreaCircSource.Length - 1
                        If sn(i) = AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(j).Location.Srcid Then
                            AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(j).Location.Xs += mxx
                            AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(j).Location.Ys += myy
                            AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(j).Location.Xs = FormatNumber(AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(j).Location.Xs, 0)
                            AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(j).Location.Ys = FormatNumber(AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(j).Location.Ys, 0)

                        End If
                    Next
                Next
            Case "build" '建筑物       
                For i As Integer = 0 To sn.Length - 1
                    For j As Integer = 0 To AermodProject0.Aermod.Bprm.ArryBldgi.Length - 1
                        If sn(i) = AermodProject0.Aermod.Bprm.ArryBldgi(j).BuildStack Then
                            For p As Integer = 0 To AermodProject0.Aermod.Bprm.ArryBldgi(j).ArryBuildTire(0).ArryBuilCorner.Length - 1
                                AermodProject0.Aermod.Bprm.ArryBldgi(j).ArryBuildTire(0).ArryBuilCorner(p).x += mxx
                                AermodProject0.Aermod.Bprm.ArryBldgi(j).ArryBuildTire(0).ArryBuilCorner(p).y += myy
                                AermodProject0.Aermod.Bprm.ArryBldgi(j).ArryBuildTire(0).ArryBuilCorner(p).x = FormatNumber(AermodProject0.Aermod.Bprm.ArryBldgi(j).ArryBuildTire(0).ArryBuilCorner(p).x, 0)
                                AermodProject0.Aermod.Bprm.ArryBldgi(j).ArryBuildTire(0).ArryBuilCorner(p).y = FormatNumber(AermodProject0.Aermod.Bprm.ArryBldgi(j).ArryBuildTire(0).ArryBuilCorner(p).y, 0)

                            Next

                        End If
                    Next
                Next
            Case "exp" '敞口源
                For i As Integer = 0 To sn.Length - 1
                    For j As Integer = 0 To AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource.Length - 1
                        If sn(i) = AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(j).Location.Srcid Then
                            AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(j).Location.Xs += mxx
                            AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(j).Location.Ys += myy
                            AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(j).Location.Xs = FormatNumber(AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(j).Location.Xs, 0)
                            AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(j).Location.Ys = FormatNumber(AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(j).Location.Ys, 0)

                            AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(j).AngleToTop()
                        End If
                    Next
                Next
            Case "rect" '矩形面源  
                For i As Integer = 0 To sn.Length - 1
                    For j As Integer = 0 To AermodProject0.Aermod.Source.AreaSources.AreaSource.Length - 1
                        If sn(i) = AermodProject0.Aermod.Source.AreaSources.AreaSource(j).Location.Srcid Then
                            AermodProject0.Aermod.Source.AreaSources.AreaSource(j).Location.Xs += mxx
                            AermodProject0.Aermod.Source.AreaSources.AreaSource(j).Location.Ys += myy
                            AermodProject0.Aermod.Source.AreaSources.AreaSource(j).Location.Xs = FormatNumber(AermodProject0.Aermod.Source.AreaSources.AreaSource(j).Location.Xs, 0)
                            AermodProject0.Aermod.Source.AreaSources.AreaSource(j).Location.Ys = FormatNumber(AermodProject0.Aermod.Source.AreaSources.AreaSource(j).Location.Ys, 0)

                            AermodProject0.Aermod.Source.AreaSources.AreaSource(j).AngleToTop()
                        End If
                    Next
                Next

        End Select
        Me.UpAllSource(ln)
        
    End Sub
    Public Sub AddGrid(ByVal gd() As CAermod.GridCart)
        If gd IsNot Nothing AndAlso gd.Length > 0 Then
            Try
                m_manager.RemoveLayer("grid")
                For i As Integer = 1 To gd.Length - 1
                    m_manager.RemoveLayer(gd(i).Netid)
                Next
                ReDim Preserve m_ArrGrid(-1)
                If gd.Length > 0 Then

                    For i As Integer = 0 To gd.Length - 1
                        ReDim Preserve m_ArrGrid(m_ArrGrid.Length)

                        If i = 0 Then

                            m_ArrGrid(m_ArrGrid.Length - 1) = New SDSGridLineLayer("grid")
                            m_manager.AddLayer(m_ArrGrid(m_ArrGrid.Length - 1))
                            m_ArrGrid(m_ArrGrid.Length - 1).LdescProperty = "主网格"
                            '网格样式
                            m_ArrGrid(m_ArrGrid.Length - 1).LineColorProperty = Color.Gray

                            'm_ArrGrid(m_ArrGrid.Length - 1).SetGridProperty(gd(i).Xinit, gd(i).Yinit, gd(i).Xnum, gd(i).Ynum, gd(i).Xdelta, gd(i).Ydelta)
                        Else
                            m_ArrGrid(m_ArrGrid.Length - 1) = New SDSGridLineLayer(gd(i).Netid)
                            m_manager.AddLayer(m_ArrGrid(m_ArrGrid.Length - 1))
                            m_ArrGrid(m_ArrGrid.Length - 1).LdescProperty = gd(i).Netid
                            '网格样式
                            m_ArrGrid(m_ArrGrid.Length - 1).LineColorProperty = Color.Gray

                            'm_ArrGrid(m_ArrGrid.Length - 1).SetGridProperty(gd(i).Xinit, gd(i).Yinit, gd(i).Xnum, gd(i).Ynum, gd(i).Xdelta, gd(i).Ydelta)
                        End If
                        If i = 0 Then
                            Assistant.SetGrid("grid", gd(i).Xinit, gd(i).Yinit _
                                              , gd(i).Xnum - 1, gd(i).Ynum - 1, gd(i).Xdelta, gd(i).Ydelta, gd(i).Xinit + AermodProject0.GetOffsetX, gd(i).Yinit + AermodProject0.GetOffsetY)
                            Assistant.SetAxis("axis", gd(i).Xinit, gd(i).Yinit _
                                              , gd(i).Xnum - 1, gd(i).Ynum - 1, gd(i).Xdelta, gd(i).Ydelta, gd(i).Xinit + AermodProject0.GetOffsetX, gd(i).Yinit + AermodProject0.GetOffsetY)
                        Else
                            '由于坐标始终都是从左下角绘制的，所以要减去相应的值
                            Assistant.SetGrid(m_ArrGrid(m_ArrGrid.Length - 1).LdescProperty, gd(i).Xinit, gd(i).Yinit _
                                              , gd(i).Xnum - 1, gd(i).Ynum - 1 _
                                            , gd(i).Xdelta, gd(i).Ydelta _
                                            , AermodProject0.GetLeftButtomUtmXY.x + (gd(i).Xinit - gd(0).Xinit), AermodProject0.GetLeftButtomUtmXY.y + (gd(i).Yinit - gd(0).Yinit))
                        End If
                    Next
                End If
            Catch ex As Exception
                MessageBox.Show("程序在删除网格图层时出错！")
            End Try
        End If


    End Sub
   
    
    Private Sub frmMainV2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.AxMap1.MouseWheelSpeed = 0.8
        '    '网格()
        '    Dim grd As New SDSGridLineLayer("grid")
        '    m_manager.AddLayer(grd)
        '    grd.LdescProperty = "主网格"
        '    '网格样式
        '    grd.LineColorProperty = Color.Gray
        '    grd.LBPointXAProperty = -500
        '    grd.LBPointYAProperty = -500
        '    grd.XCellsProperty = 100
        '    grd.YCellsProperty = 100
        '    grd.XunitLProperty = 10
        '    grd.YuintLProperty = 10
        '    '坐标轴
        '    Dim axis As New SDSAxisLayer("axis")
        '    m_manager.AddLayer(axis)

        '    axis.LdescProperty = "坐标轴"
        '    axis.LBPointXAProperty = -500
        '    axis.LBPointYAProperty = -500

        '    axis.XCellsProperty = 100
        '    axis.YCellsProperty = 100

        '    axis.XunitLProperty = 10
        '    axis.YuintLProperty = 10

        '    axis.LBPointXProperty = -500
        '    axis.LBPointYProperty = -500

        '    axis.ScaleLProperty = 5
        '    ''来个小网格
        '    'Dim grd As New SDSGridLineLayer("grid")
        '    'grd.LdescProperty = "主网格"
        '    'm_manager.AddLayer(grd)


        '    ' ''等值线
        '    ''Dim con As New SDSContourLayer("contour")
        '    ''m_manager.AddLayer(con)


        '    ''坐标轴
        '    'Dim axis As New SDSAxisLayer("axis")
        '    'axis.LdescProperty = "坐标轴"
        '    'm_manager.AddLayer(axis)

        '    '建筑物
        '    Dim layer9 As New ESPolylineLayer("build", New PolyTool)
        '    layer9.LdescProperty = "建筑物"
        '    m_manager.AddLayer(layer9)


        '    '点源
        '    Dim cpLayer2 As New ESPointLayer("ppoint", New PointTool)
        '    cpLayer2.LdescProperty = "点源"
        '    m_manager.AddLayer(cpLayer2)

        '    '体源
        '    Dim layer5 As New ESPolylineLayer("cube", New SquareTool)
        '    layer5.LdescProperty = "体源"
        '    m_manager.AddLayer(layer5)

        '    '矩形面源
        '    Dim layer7 As New ESPolylineLayer("rect", New RectangleTool)
        '    layer7.LdescProperty = "矩形面源"
        '    m_manager.AddLayer(layer7)

        '    '多边形源
        '    Dim layer4 As New ESPolylineLayer("poly", New PolyTool)
        '    layer4.LdescProperty = "多边形源"
        '    m_manager.AddLayer(layer4)

        '    '圆形面源
        '    Dim layer6 As New ESCriclePolyLayer("circle", New CircleToolV3)
        '    layer6.LdescProperty = "圆形面源"
        '    m_manager.AddLayer(layer6)

        '    '敞口源
        '    Dim layer8 As New ESPolylineLayer("exp", New RectangleTool)
        '    layer8.LdescProperty = "敞口源"
        '    m_manager.AddLayer(layer8)

        '    '线源
        '    Dim layer3 As New ESMLineLayer("pline", New CPlineTool)
        '    layer3.LdescProperty = "线源"
        '    m_manager.AddLayer(layer3)




        '    ' 关心点 点层的例子，哈哈
        '    Dim cpLayer As New ESPointLayer("cpoint", New PointTool)
        '    cpLayer.LdescProperty = "关心点"
        '    m_manager.AddLayer(cpLayer)

        '    Assistant.m_manager = Me.m_manager

    End Sub

    Public Sub AddImage(ByVal LayName As String, ByVal path As String, ByVal p1 As PointF, ByVal p2 As PointF, ByVal pl1 As PointF, ByVal pl2 As PointF)
        Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
        Assistant.AddImage(LayName, path, p1, p2, pl1, pl2, "grid", "axis", PublicVal.AermodProject0.GetOffsetX, PublicVal.AermodProject0.GetOffsetY, myFrmMain.m_tree, PublicVal.BackImage0.InsertImageCollection.Count - 1)
    End Sub

    Public Sub AddAllPointSource(ByVal ln As String, ByVal list As List(Of GisMapF.FEntity))

    End Sub
    ''' <summary>
    ''' 根据污染源更新方案
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SetProjectSoure()
        '新增加的方案的代码
        '设置污染源
        AermodProject0.Aermod.Source.Groups.ResetGroupSource(AermodProject0.Aermod.Source)
        If AermodProject0.ProjSetCollection IsNot Nothing Then
            For Index As Integer = 0 To AermodProject0.ProjSetCollection.Count - 1
                AermodProject0.ProjSetCollection.Item(Index).GroupsCollection.ResetGroupSource(AermodProject0.Aermod.Source) '根据用户修改所有的污染源组中的污染源
            Next
        End If
    End Sub
    ''' <summary>
    ''' 根据关心点更新方案
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SetProjectReceptor()
        '新增加的方案的代码
        '设置关心点
        For Index As Integer = 0 To AermodProject0.ProjSetCollection.Count - 1
            AermodProject0.ProjSetCollection.Item(Index).InitalReceptorSelected(AermodProject0.Aermod.Receptor) '根据用户修改所有的方案中的关心点
        Next
    End Sub

    ''' <summary>
    ''' 增加污染源和关心点等
    ''' </summary>
    ''' <param name="ln"></param>
    ''' <param name="pt"></param>
    ''' <param name="type"></param>
    ''' <remarks></remarks>
    Private Sub OnAskAdd(ByVal ln As String, ByVal pt As MapWinGIS.Point(), ByVal type As String)
        Select Case ln
            Case "cpoint" '增加关心点
                Dim dlgCare As New dlgSingleDiscCart
                '获取相对坐标
                Dim x As Double = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).x
                Dim y As Double = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).y
                x = FormatNumber(x, 0)
                y = FormatNumber(y, 0)
                dlgCare.txtName.Text = "计算点" & AermodProject0.Aermod.Receptor.nDiscCart + 1
                dlgCare.txtXcoord.Value = x
                dlgCare.txtYcoord.Value = y

                If dlgCare.ShowDialog = Windows.Forms.DialogResult.OK Then
                    '
                    '
                    ReDim Preserve AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length)
                    AermodProject0.Aermod.Receptor.nDiscCart = AermodProject0.Aermod.Receptor.nDiscCart + 1
                    AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1) = New CAermod.DiscCart
                    AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1).ID = AermodProject0.Aermod.Receptor.nDiscCart
                    AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1).Name = dlgCare.txtName.Text
                    AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1).Xcoord = dlgCare.txtXcoord.Value
                    AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1).Ycoord = dlgCare.txtYcoord.Value
                    AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1).Xcoord = FormatNumber(AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1).Xcoord, 2)
                    AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1).Ycoord = FormatNumber(AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1).Ycoord, 2)
                    AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1).Zelev = dlgCare.txtZelev.Value
                    AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1).Zhill = dlgCare.txtZhill.Value
                    AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1).Zflag = dlgCare.txtZflag.Value


                    Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
                    myFrmMain.SolutionExplorer.RefreshSolutionTree() '根据用户的设置修改方案中的个数

                    Dim cpLayer As EditableShapeLayer
                    m_manager.GetLayer(ln, cpLayer)

                    If cpLayer IsNot Nothing Then

                        Dim ptA(0) As MapWinGIS.Point
                        ptA(0) = New MapWinGIS.Point
                        ptA(0).x = Me.GetUtmFromRelative(dlgCare.txtXcoord.Value, dlgCare.txtYcoord.Value).x
                        ptA(0).y = Me.GetUtmFromRelative(dlgCare.txtXcoord.Value, dlgCare.txtYcoord.Value).y
                        ptA(0).x = FormatNumber(ptA(0).x, 0)
                        ptA(0).y = FormatNumber(ptA(0).y, 0)
                        cpLayer.AddEntity(AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1).ID _
                                          , ptA, AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 1).Name)
                    Else
                        MessageBox.Show("未找到对应的层")

                    End If
                    AermodProject0.Aermod.BackCon.PolluteChaged(AermodProject0.Aermod.Control.AllPolluts, AermodProject0.Aermod.Receptor.DiscCarts)
                    '根据关心点更新方案
                    SetProjectReceptor()
                End If
            Case "ppoint" '增加点源
                Dim dlgPoint As New dlgPointsSource
                'dlgPoint.Modify()
                dlgPoint.Urbans = AermodProject0.Aermod.Control.Urbans.Clone
                dlgPoint.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut.Clone  '所有选中的污染物
                dlgPoint.Control = AermodProject0.Aermod.Control.Clone
                dlgPoint.SourceCount = AermodProject0.Aermod.Source.PointSources.nStack

                Dim ps As New CAermod.PointSources
                ps = AermodProject0.Aermod.Source.PointSources.Clone
                '增加污染物
                ReDim Preserve ps.PointSource(ps.PointSource.Length)
                ps.PointSource(ps.PointSource.Length - 1) = New CAermod.PointSource
                ReDim ps.PointSource(ps.PointSource.Length - 1).PollutionPara(dlgPoint.ArrayPollut.Length - 1) '设置新增加的污染源的污染物的类型
                ps.PointSource(ps.PointSource.Length - 1).PollutionPara(dlgPoint.ArrayPollut.Length - 1) = New CAermod.PollutionPara
                ps.PointSource(ps.PointSource.Length - 1).SetPollutePara(AermodProject0.Aermod.Control.AllPolluts)
                ps.PointSource(ps.PointSource.Length - 1).Location.Srcid = "P" & (dlgPoint.SourceCount + 1)
                dlgPoint.SourceCount += 1
                ps.PointSource(ps.PointSource.Length - 1).SourceName = "点源" & dlgPoint.SourceCount '污染源名称

                '获取相对坐标
                Dim x As Double = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).x
                Dim y As Double = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).y

                ps.PointSource(ps.PointSource.Length - 1).Location.Xs = FormatNumber(x, 0, TriState.True, TriState.False, TriState.False)
                ps.PointSource(ps.PointSource.Length - 1).Location.Ys = FormatNumber(y, 0, TriState.True, TriState.False, TriState.False)

                dlgPoint.BaseSoruce = ps.PointSource
                dlgPoint.IntialSelectedIndex = ps.PointSource.Length - 1

                If dlgPoint.ShowDialog = Windows.Forms.DialogResult.OK Then
                    ps.PointSource = CType(dlgPoint.BaseSoruce, CAermod.PointSource())
                    AermodProject0.Aermod.Source.PointSources = ps.Clone
                 
                    AermodProject0.Aermod.Source.PointSources.nStack = dlgPoint.SourceCount
                    AermodProject0.Aermod.Source.Groups.ResetGroupSource(AermodProject0.Aermod.Source) '根据用户修改的污染源修改组中的污染源
                    Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
                    myFrmMain.SolutionExplorer.RefreshSolutionTree() '根据用户的设置修改方案中的个数

                    Dim cpLayer As EditableShapeLayer
                    m_manager.GetLayer(ln, cpLayer)

                    If cpLayer IsNot Nothing Then

                        Dim ptA(0) As MapWinGIS.Point
                        ptA(0) = New MapWinGIS.Point
                        ptA(0).x = Me.GetUtmFromRelative(ps.PointSource(ps.PointSource.Length - 1).Location.Xs, ps.PointSource(ps.PointSource.Length - 1).Location.Ys).x
                        ptA(0).y = Me.GetUtmFromRelative(ps.PointSource(ps.PointSource.Length - 1).Location.Xs, ps.PointSource(ps.PointSource.Length - 1).Location.Ys).y
                        cpLayer.AddEntity(ps.PointSource(ps.PointSource.Length - 1).Location.Srcid, ptA, ps.PointSource(ps.PointSource.Length - 1).SourceName)
                    Else
                        MessageBox.Show("未找到对应的层")

                    End If
                    '根据用户的设置修改方案中的个数
                    SetProjectSoure()
                End If

            Case "pline" '增加线源
                Dim dlgLine As New dlgLineSources
                'dlgLine.Modify()
                dlgLine.Urbans = AermodProject0.Aermod.Control.Urbans
                dlgLine.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut '所有选中的污染物
                dlgLine.Control = AermodProject0.Aermod.Control
                dlgLine.SourceCount = AermodProject0.Aermod.Source.LineSources.nStack
                '增加污染物
                Dim ps As CAermod.LineSources
                ps = AermodProject0.Aermod.Source.LineSources.Clone
                ReDim Preserve ps.ArrayLineSources(ps.ArrayLineSources.Length)
                ps.ArrayLineSources(ps.ArrayLineSources.Length - 1) = New CAermod.Line
                ReDim ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).PollutionPara(dlgLine.ArrayPollut.Length - 1) '设置新增加的污染源的污染物的类型
                ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).PollutionPara(dlgLine.ArrayPollut.Length - 1) = New CAermod.PollutionPara
                ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).SetPollutePara(AermodProject0.Aermod.Control.AllPolluts)
                ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).Location.Srcid = "L" & (dlgLine.SourceCount + 1)
                dlgLine.SourceCount += 1
                '初始化污染物的名称
                ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).SourceName = "线源" & dlgLine.SourceCount '污染源名称

                '设置第一个顶点坐标
                Dim P As PointF
                P.X = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).x
                P.Y = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).y
                ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).Location.Xs = FormatNumber(P.X, 0)
                ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).Location.Ys = FormatNumber(P.Y, 0)


                '设置其它顶点
                Dim AF(pt.Length - 1) As PointF
                Dim AP(pt.Length - 1) As Point
                For i As Integer = 0 To pt.Length - 1
                    AF(i).X = Me.GetRelativelyCoordinate(pt(i).x, pt(i).y).x
                    AF(i).Y = Me.GetRelativelyCoordinate(pt(i).x, pt(i).y).y
                    AP(i).X = AF(i).X
                    AP(i).Y = AF(i).Y
                Next
                ReDim CType(ps.ArrayLineSources(ps.ArrayLineSources.Length - 1), CAermod.Line).LinePoints(AP.Length - 1)
                CType(ps.ArrayLineSources(ps.ArrayLineSources.Length - 1), CAermod.Line).LinePoints(0) = New CAermod.Point3D
                CType(ps.ArrayLineSources(ps.ArrayLineSources.Length - 1), CAermod.Line).LinePoints(0).x = ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).Location.Xs
                CType(ps.ArrayLineSources(ps.ArrayLineSources.Length - 1), CAermod.Line).LinePoints(0).y = ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).Location.Ys
                For i As Integer = 0 To AP.Length - 1
                    CType(ps.ArrayLineSources(ps.ArrayLineSources.Length - 1), CAermod.Line).LinePoints(i) = New CAermod.Point3D
                    CType(ps.ArrayLineSources(ps.ArrayLineSources.Length - 1), CAermod.Line).LinePoints(i).x = AP(i).X
                    CType(ps.ArrayLineSources(ps.ArrayLineSources.Length - 1), CAermod.Line).LinePoints(i).y = AP(i).Y
                Next


                dlgLine.BaseSoruce = ps.ArrayLineSources
                dlgLine.IntialSelectedIndex = dlgLine.BaseSoruce.Length - 1
                If dlgLine.ShowDialog = Windows.Forms.DialogResult.OK Then
                    ps.ArrayLineSources = dlgLine.BaseSoruce
                    AermodProject0.Aermod.Source.LineSources = ps.Clone
                    AermodProject0.Aermod.Source.LineSources.nStack = dlgLine.SourceCount
                    AermodProject0.Aermod.Source.Groups.ResetGroupSource(AermodProject0.Aermod.Source) '根据用户修改的污染源修改组中的污染源
                    Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
                    myFrmMain.SolutionExplorer.RefreshSolutionTree() '根据用户的设置修改方案中的个数



                    Dim cpLayer As ESMLineLayer
                    m_manager.GetLayer(ln, cpLayer)

                    If cpLayer IsNot Nothing Then

                        Dim ptA(ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).LinePoints.Length) As MapWinGIS.Point
                        ptA(0) = New MapWinGIS.Point
                        ptA(0).x = Me.GetUtmFromRelative(ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).Location.Xs, ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).Location.Ys).x
                        ptA(0).y = Me.GetUtmFromRelative(ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).Location.Xs, ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).Location.Ys).y

                        For i As Integer = 0 To ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).LinePoints.Length - 1
                            ptA(i + 1) = New MapWinGIS.Point
                            ptA(i + 1).x = Me.GetUtmFromRelative(ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).LinePoints(i).x, ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).LinePoints(i).y).x
                            ptA(i + 1).y = Me.GetUtmFromRelative(ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).LinePoints(i).x, ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).LinePoints(i).y).y
                        Next

                        cpLayer.AddEntity(ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).Location.Srcid, ptA, ps.ArrayLineSources(ps.ArrayLineSources.Length - 1).SourceName)
                    Else
                        MessageBox.Show("未找到对应的层")

                    End If
                    '根据用户的设置修改方案中的个数
                    SetProjectSoure()
                End If
            Case "poly" '多边形
                Dim dlgAreaPoly As New dlgAreaPolySource
                'dlgAreaPoly.Modify()  小杨注释
                dlgAreaPoly.Urbans = AermodProject0.Aermod.Control.Urbans
                dlgAreaPoly.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut '所有选中的污染物
                dlgAreaPoly.Control = AermodProject0.Aermod.Control
                dlgAreaPoly.SourceCount = AermodProject0.Aermod.Source.AreaPolySources.nStack
                '增加污染物
                Dim ps As CAermod.AreaPolySources
                ps = AermodProject0.Aermod.Source.AreaPolySources.Clone
                ReDim Preserve ps.AreaPolySource(ps.AreaPolySource.Length)
                ps.AreaPolySource(ps.AreaPolySource.Length - 1) = New CAermod.AreaPolySource
                ReDim ps.AreaPolySource(ps.AreaPolySource.Length - 1).PollutionPara(dlgAreaPoly.ArrayPollut.Length - 1) '设置新增加的污染源的污染物的类型
                ps.AreaPolySource(ps.AreaPolySource.Length - 1).PollutionPara(dlgAreaPoly.ArrayPollut.Length - 1) = New CAermod.PollutionPara
                ps.AreaPolySource(ps.AreaPolySource.Length - 1).SetPollutePara(AermodProject0.Aermod.Control.AllPolluts)
                ps.AreaPolySource(ps.AreaPolySource.Length - 1).Location.Srcid = "AP" & (dlgAreaPoly.SourceCount + 1)
                dlgAreaPoly.SourceCount += 1
                '初始化污染物的名称
                ps.AreaPolySource(ps.AreaPolySource.Length - 1).SourceName = "多边形面源" & dlgAreaPoly.SourceCount '污染源名称

                '设置第一个顶点坐标
                Dim P As PointF
                P.X = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).x
                P.Y = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).y
                ps.AreaPolySource(ps.AreaPolySource.Length - 1).Location.Xs = FormatNumber(P.X, 0)
                ps.AreaPolySource(ps.AreaPolySource.Length - 1).Location.Ys = FormatNumber(P.Y, 0)


                '设置其它顶点
                Dim AF(pt.Length - 2) As PointF
                Dim AP(pt.Length - 2) As Point
                For i As Integer = 1 To pt.Length - 1
                    AF(i - 1).X = Me.GetRelativelyCoordinate(pt(i).x, pt(i).y).x
                    AF(i - 1).Y = Me.GetRelativelyCoordinate(pt(i).x, pt(i).y).y

                    AP(i - 1).X = AF(i - 1).X
                    AP(i - 1).Y = AF(i - 1).Y
                Next
                CType(ps.AreaPolySource(ps.AreaPolySource.Length - 1), CAermod.AreaPolySource).SetVerts(AP)

                dlgAreaPoly.BaseSoruce = ps.AreaPolySource
                dlgAreaPoly.IntialSelectedIndex = dlgAreaPoly.BaseSoruce.Length - 1
                If dlgAreaPoly.ShowDialog = Windows.Forms.DialogResult.OK Then
                    ps.AreaPolySource = dlgAreaPoly.BaseSoruce
                    AermodProject0.Aermod.Source.AreaPolySources = ps.Clone
                    AermodProject0.Aermod.Source.AreaPolySources.nStack = dlgAreaPoly.SourceCount
                    AermodProject0.Aermod.Source.Groups.ResetGroupSource(AermodProject0.Aermod.Source) '根据用户修改的污染源修改组中的污染源
                    Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
                    myFrmMain.SolutionExplorer.RefreshSolutionTree() '根据用户的设置修改方案中的个数

                    Dim cpLayer As ESPolygonLayer
                    m_manager.GetLayer(ln, cpLayer)

                    If cpLayer IsNot Nothing Then

                        Dim ptA(ps.AreaPolySource(ps.AreaPolySource.Length - 1).GetVerts.Length) As MapWinGIS.Point
                        ptA(0) = New MapWinGIS.Point
                        ptA(0).x = Me.GetUtmFromRelative(ps.AreaPolySource(ps.AreaPolySource.Length - 1).Location.Xs, ps.AreaPolySource(ps.AreaPolySource.Length - 1).Location.Ys).x
                        ptA(0).y = Me.GetUtmFromRelative(ps.AreaPolySource(ps.AreaPolySource.Length - 1).Location.Xs, ps.AreaPolySource(ps.AreaPolySource.Length - 1).Location.Ys).y

                        For i As Integer = 0 To ps.AreaPolySource(ps.AreaPolySource.Length - 1).GetVerts.Length - 1
                            ptA(i + 1) = New MapWinGIS.Point
                            ptA(i + 1).x = Me.GetUtmFromRelative(ps.AreaPolySource(ps.AreaPolySource.Length - 1).GetVerts(i).X, ps.AreaPolySource(ps.AreaPolySource.Length - 1).GetVerts(i).Y).x
                            ptA(i + 1).y = Me.GetUtmFromRelative(ps.AreaPolySource(ps.AreaPolySource.Length - 1).GetVerts(i).X, ps.AreaPolySource(ps.AreaPolySource.Length - 1).GetVerts(i).Y).y
                        Next

                        cpLayer.AddEntity(ps.AreaPolySource(ps.AreaPolySource.Length - 1).Location.Srcid, ptA, ps.AreaPolySource(ps.AreaPolySource.Length - 1).SourceName)
                    Else
                        MessageBox.Show("未找到对应的层")

                    End If
                    '根据用户的设置修改方案中的个数
                    SetProjectSoure()
                End If

            Case "cube" '体源
                Dim dlgVolume As New dlgVolumeSource
                'dlgVolume.Modify()
                dlgVolume.Urbans = AermodProject0.Aermod.Control.Urbans
                dlgVolume.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut '所有选中的污染物
                dlgVolume.Control = AermodProject0.Aermod.Control
                dlgVolume.SourceCount = AermodProject0.Aermod.Source.VolumeSources.nStack
                '增加污染物
                Dim ps As CAermod.VolumeSources
                ps = AermodProject0.Aermod.Source.VolumeSources.Clone
                ReDim Preserve ps.VolumeSource(ps.VolumeSource.Length)
                ps.VolumeSource(ps.VolumeSource.Length - 1) = New CAermod.VolumeSource
                ReDim ps.VolumeSource(ps.VolumeSource.Length - 1).PollutionPara(dlgVolume.ArrayPollut.Length - 1) '设置新增加的污染源的污染物的类型
                ps.VolumeSource(ps.VolumeSource.Length - 1).PollutionPara(dlgVolume.ArrayPollut.Length - 1) = New CAermod.PollutionPara
                ps.VolumeSource(ps.VolumeSource.Length - 1).SetPollutePara(AermodProject0.Aermod.Control.AllPolluts)
                ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Srcid = "VL" & (dlgVolume.SourceCount + 1)
                dlgVolume.SourceCount += 1
                '初始化污染物的名称
                ps.VolumeSource(ps.VolumeSource.Length - 1).SourceName = "体源" & dlgVolume.SourceCount '污染源名称

                '获取相对坐标
                Dim x0 As Double = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).x
                Dim y0 As Double = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).y
                Dim x2 As Double = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).x
                Dim y2 As Double = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).y
                Dim CenterPoint As New PointF
                CenterPoint.X = (x0 + x2) / 2
                CenterPoint.Y = (y0 + y2) / 2

                ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Xs = FormatNumber(CenterPoint.X, 0, TriState.True, TriState.False, TriState.False)
                ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Ys = FormatNumber(CenterPoint.Y, 0, TriState.True, TriState.False, TriState.False)

                Dim Width As Single
                Width = Math.Abs(x2 - x0)
                CType(ps.VolumeSource(ps.VolumeSource.Length - 1), CAermod.VolumeSource).Width = Width

                dlgVolume.BaseSoruce = ps.VolumeSource
                dlgVolume.IntialSelectedIndex = dlgVolume.BaseSoruce.Length - 1
                If dlgVolume.ShowDialog = Windows.Forms.DialogResult.OK Then

                    '根据结果来修改方案
                    ps.VolumeSource = CType(dlgVolume.BaseSoruce, CAermod.VolumeSource())
                    AermodProject0.Aermod.Source.VolumeSources = ps.Clone
                    AermodProject0.Aermod.Source.VolumeSources.nStack = dlgVolume.SourceCount
                    AermodProject0.Aermod.Source.Groups.ResetGroupSource(AermodProject0.Aermod.Source) '根据用户修改的污染源修改组中的污染源
                    Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
                    myFrmMain.SolutionExplorer.RefreshSolutionTree() '根据用户的设置修改方案中的个数

                    Dim cpLayer As ESPolygonLayer
                    m_manager.GetLayer(ln, cpLayer)

                    If cpLayer IsNot Nothing Then

                        Dim ptA(3) As MapWinGIS.Point
                        ptA(0) = New MapWinGIS.Point
                        ptA(0).x = Me.GetUtmFromRelative(ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Xs - ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2, ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Ys - ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2).x
                        ptA(0).y = Me.GetUtmFromRelative(ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Xs - ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2, ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Ys - ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2).y

                        ptA(1) = New MapWinGIS.Point
                        ptA(1).x = Me.GetUtmFromRelative(ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Xs - ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2, ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Ys + ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2).x
                        ptA(1).y = Me.GetUtmFromRelative(ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Xs - ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2, ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Ys + ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2).y

                        ptA(2) = New MapWinGIS.Point
                        ptA(2).x = Me.GetUtmFromRelative(ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Xs + ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2, ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Ys + ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2).x
                        ptA(2).y = Me.GetUtmFromRelative(ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Xs + ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2, ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Ys + ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2).y

                        ptA(3) = New MapWinGIS.Point
                        ptA(3).x = Me.GetUtmFromRelative(ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Xs + ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2, ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Ys - ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2).x
                        ptA(3).y = Me.GetUtmFromRelative(ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Xs + ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2, ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Ys - ps.VolumeSource(ps.VolumeSource.Length - 1).Width / 2).y

                        cpLayer.AddEntity(ps.VolumeSource(ps.VolumeSource.Length - 1).Location.Srcid, ptA, ps.VolumeSource(ps.VolumeSource.Length - 1).SourceName)
                    Else
                        MessageBox.Show("未找到对应的层")

                    End If
                    '根据用户的设置修改方案中的个数
                    SetProjectSoure()
                End If
            Case "circle" '圆形面源
                Dim dlgCircle As New dlgAreaCircSource
                'dlgCircle.Modify()‘小杨注释
                dlgCircle.Urbans = AermodProject0.Aermod.Control.Urbans
                dlgCircle.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut '所有选中的污染物
                dlgCircle.Control = AermodProject0.Aermod.Control
                dlgCircle.SourceCount = AermodProject0.Aermod.Source.AreacircSources.nStack
                '增加污染物
                Dim ps As CAermod.AreaCircSources
                ps = AermodProject0.Aermod.Source.AreacircSources.Clone

                ReDim Preserve ps.AreaCircSource(ps.AreaCircSource.Length)
                ps.AreaCircSource(ps.AreaCircSource.Length - 1) = New CAermod.AreaCircSource
                ReDim ps.AreaCircSource(ps.AreaCircSource.Length - 1).PollutionPara(dlgCircle.ArrayPollut.Length - 1) '设置新增加的污染源的污染物的类型
                ps.AreaCircSource(ps.AreaCircSource.Length - 1).PollutionPara(dlgCircle.ArrayPollut.Length - 1) = New CAermod.PollutionPara
                ps.AreaCircSource(ps.AreaCircSource.Length - 1).SetPollutePara(AermodProject0.Aermod.Control.AllPolluts)
                ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Srcid = "AC" & (dlgCircle.SourceCount + 1)
                dlgCircle.SourceCount += 1
                '初始化污染物的名称
                ps.AreaCircSource(ps.AreaCircSource.Length - 1).SourceName = "圆形面源" & dlgCircle.SourceCount '污染源名称
                '设置第一个圆心坐标
                'Dim P1 As PointF
                'P1.X = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).x
                'P1.Y = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).y

                'ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Xs = FormatNumber(P1.X, 0)
                'ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Ys = FormatNumber(P1.Y, 0)
                ''计算半径
                'Dim P2 As PointF
                'P2.X = Me.GetRelativelyCoordinate(pt(1).x, pt(1).y).x
                'P2.Y = Me.GetRelativelyCoordinate(pt(1).x, pt(1).y).y

                'Dim R As Double = DrawContour.PublicFun.Distance(P1, P2)
                'R = FormatNumber(R, 2)
                Dim x0 As Double = (pt(pt.Length / 2 - 1).x + pt(0).x) / 2
                Dim y0 As Double = (pt(pt.Length / 2 - 1).y + pt(0).y) / 2

                Dim x As Double = Me.GetRelativelyCoordinate(x0, y0).x
                Dim y As Double = Me.GetRelativelyCoordinate(x0, y0).y
                ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Xs = FormatNumber(x, 0, TriState.True, TriState.False, TriState.False)
                ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Ys = FormatNumber(y, 0, TriState.True, TriState.False, TriState.False)
                ps.AreaCircSource(ps.AreaCircSource.Length - 1).Radius = ((pt(pt.Length / 2 - 1).x - pt(0).x) ^ 2) + ((pt(pt.Length / 2 - 1).y - pt(0).y) ^ 2)

                ps.AreaCircSource(ps.AreaCircSource.Length - 1).Radius = Math.Sqrt(ps.AreaCircSource(ps.AreaCircSource.Length - 1).Radius) / 2
                ps.AreaCircSource(ps.AreaCircSource.Length - 1).Radius = FormatNumber(ps.AreaCircSource(ps.AreaCircSource.Length - 1).Radius, 2)
                '设置半径
                'CType(ps.AreaCircSource(ps.AreaCircSource.Length - 1), CAermod.AreaCircSource).Radius = R

                dlgCircle.BaseSoruce = ps.AreaCircSource
                dlgCircle.IntialSelectedIndex = dlgCircle.BaseSoruce.Length - 1
                If dlgCircle.ShowDialog = Windows.Forms.DialogResult.OK Then
                    ps.AreaCircSource = dlgCircle.BaseSoruce
                    AermodProject0.Aermod.Source.AreacircSources = ps.Clone
                    AermodProject0.Aermod.Source.AreacircSources.nStack = dlgCircle.SourceCount
                    AermodProject0.Aermod.Source.Groups.ResetGroupSource(AermodProject0.Aermod.Source) '根据用户修改的污染源修改组中的污染源
                    Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
                    myFrmMain.SolutionExplorer.RefreshSolutionTree() '根据用户的设置修改方案中的个数


                    Dim cpLayer As ESPolygonLayer
                    m_manager.GetLayer(ln, cpLayer)

                    'If cpLayer IsNot Nothing Then

                    '    Dim ptA(1) As MapWinGIS.Point
                    '    ptA(0) = New MapWinGIS.Point
                    '    ptA(0).x = Me.GetUtmFromRelative(ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Xs, ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Ys).x
                    '    ptA(0).y = Me.GetUtmFromRelative(ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Xs, ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Ys).y

                    '    ptA(1) = New MapWinGIS.Point
                    '    ptA(1).x = ptA(0).x + ps.AreaCircSource(ps.AreaCircSource.Length - 1).Radius
                    '    ptA(1).y = ptA(0).y

                    '    cpLayer.AddEntity(ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Srcid, ptA, ps.AreaCircSource(ps.AreaCircSource.Length - 1).SourceName)
                    'Else
                    '    MessageBox.Show("未找到对应的层")

                    'End If

                    If cpLayer IsNot Nothing Then
                        Dim pb As New List(Of MapWinGIS.Point)
                        Dim ptA(0) As MapWinGIS.Point
                        'Dim ptA(1) As MapWinGIS.Point
                        ptA(0) = New MapWinGIS.Point
                        ptA(0).x = Me.GetUtmFromRelative(ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Xs, ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Ys).x
                        ptA(0).y = Me.GetUtmFromRelative(ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Xs, ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Ys).y


                        'Me.CirclePoints(ptA, m_frmHCircleSource.HCirleAreaSourceCollection(0).R)
                        Dim rr As Double = AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(AermodProject0.Aermod.Source.AreacircSources.AreaCircSource.Length - 1).Radius
                        Dim ptReturn As New List(Of MapWinGIS.Point)

                        For i As Double = 0 To 2 * Math.PI Step Math.PI / 360
                            Dim pTemp As New MapWinGIS.Point
                            pTemp.x = rr * Math.Cos(i) + ptA(0).x
                            pTemp.y = rr * Math.Sin(i) + ptA(0).y
                            ptReturn.Add(pTemp)
                        Next

                        cpLayer.AddEntity(ps.AreaCircSource(ps.AreaCircSource.Length - 1).Location.Srcid, ptReturn.ToArray(), ps.AreaCircSource(ps.AreaCircSource.Length - 1).SourceName)
                    Else
                        MessageBox.Show("未找到对应的层")
                    End If
                    '根据用户的设置修改方案中的个数
                    SetProjectSoure()
                End If
            Case "rect" '矩形面源


                Dim K1 As Double = 0 '斜率
                Dim K2 As Double = 0 '垂线的斜率
                '计算出斜率K1
                Dim P1, P20, P2, P3, P4 As PointF '用于表示4个顶点
                Dim AngleX As Double
                '求出与Y的夹角
                Dim AngleY As Double
                '求出Y边长
                Dim LengY As Double
                '求出X边长
                Dim LengX As Double
                Dim dlgArea As New dlgAreaSource
                'dlgArea.Modify()
                dlgArea.Urbans = AermodProject0.Aermod.Control.Urbans
                dlgArea.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut '所有选中的污染物
                dlgArea.Control = AermodProject0.Aermod.Control
                dlgArea.SourceCount = AermodProject0.Aermod.Source.AreaSources.nStack
                '增加污染物
                Dim ps As CAermod.AreaSources
                ps = AermodProject0.Aermod.Source.AreaSources.Clone

                ReDim Preserve ps.AreaSource(ps.AreaSource.Length)
                ps.AreaSource(ps.AreaSource.Length - 1) = New CAermod.AreaSource
                ReDim ps.AreaSource(ps.AreaSource.Length - 1).PollutionPara(dlgArea.ArrayPollut.Length - 1) '设置新增加的污染源的污染物的类型
                ps.AreaSource(ps.AreaSource.Length - 1).PollutionPara(dlgArea.ArrayPollut.Length - 1) = New CAermod.PollutionPara
                ps.AreaSource(ps.AreaSource.Length - 1).SetPollutePara(AermodProject0.Aermod.Control.AllPolluts)
                ps.AreaSource(ps.AreaSource.Length - 1).Location.Srcid = "AR" & (dlgArea.SourceCount + 1)
                dlgArea.SourceCount += 1
                '初始化污染物的名称
                ps.AreaSource(ps.AreaSource.Length - 1).SourceName = "矩形面源" & dlgArea.SourceCount '污染源名称
                AermodProject0.Aermod.Source.Groups.ResetGroupSource(AermodProject0.Aermod.Source) '根据用户修改的污染源修改组中的污染源


                If Math.Abs(pt(0).x - pt(1).x) < 1 Or Math.Abs(pt(0).y - pt(1).y) < 1 Then
                    '设置4个角
                    If Math.Abs(pt(0).x - pt(1).x) < 1 Then
                        P1.X = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).x
                        P1.Y = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).y
                        P3.X = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).x
                        P3.Y = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).y

                        P2.X = P1.X
                        P2.Y = P3.Y
                        P4.X = P3.X
                        P4.Y = P1.Y
                    ElseIf Math.Abs(pt(0).y - pt(1).y) < 1 Then '直角没有斜率
                        P1.X = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).x
                        P1.Y = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).y
                        P3.X = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).x
                        P3.Y = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).y
                        P2.X = P3.X
                        P2.Y = P1.Y
                        P4.X = P1.X
                        P4.Y = P3.Y
                    End If

                    '设置顶点、角度和边长
                    If P1.Y > P3.Y Then
                        If P1.X < P3.X Then
                            ps.AreaSource(ps.AreaSource.Length - 1).Angle = 90
                            ps.AreaSource(ps.AreaSource.Length - 1).Location.Xs = FormatNumber(P1.X, 0, TriState.True, TriState.False, TriState.False)
                            ps.AreaSource(ps.AreaSource.Length - 1).Location.Ys = FormatNumber(P1.Y, 0, TriState.True, TriState.False, TriState.False)

                            ps.AreaSource(ps.AreaSource.Length - 1).Yinit = Math.Abs(P3.X - P1.X)
                            ps.AreaSource(ps.AreaSource.Length - 1).Xinit = Math.Abs(P3.Y - P1.Y)
                        Else
                            ps.AreaSource(ps.AreaSource.Length - 1).Angle = 0
                            ps.AreaSource(ps.AreaSource.Length - 1).Location.Xs = FormatNumber(P3.X, 0, TriState.True, TriState.False, TriState.False)
                            ps.AreaSource(ps.AreaSource.Length - 1).Location.Ys = FormatNumber(P3.Y, 0, TriState.True, TriState.False, TriState.False)

                            ps.AreaSource(ps.AreaSource.Length - 1).Yinit = Math.Abs(P3.Y - P1.Y)
                            ps.AreaSource(ps.AreaSource.Length - 1).Xinit = Math.Abs(P3.X - P1.X)
                        End If
                    Else
                        If P1.X < P3.X Then
                            ps.AreaSource(ps.AreaSource.Length - 1).Angle = 0
                            ps.AreaSource(ps.AreaSource.Length - 1).Location.Xs = FormatNumber(P1.X, 0, TriState.True, TriState.False, TriState.False)
                            ps.AreaSource(ps.AreaSource.Length - 1).Location.Ys = FormatNumber(P1.Y, 0, TriState.True, TriState.False, TriState.False)
                            ps.AreaSource(ps.AreaSource.Length - 1).Yinit = Math.Abs(P3.Y - P1.Y)
                            ps.AreaSource(ps.AreaSource.Length - 1).Xinit = Math.Abs(P3.X - P1.X)
                        Else
                            ps.AreaSource(ps.AreaSource.Length - 1).Angle = 90
                            ps.AreaSource(ps.AreaSource.Length - 1).Location.Xs = FormatNumber(P3.X, 0, TriState.True, TriState.False, TriState.False)
                            ps.AreaSource(ps.AreaSource.Length - 1).Location.Ys = FormatNumber(P3.Y, 0, TriState.True, TriState.False, TriState.False)
                            ps.AreaSource(ps.AreaSource.Length - 1).Yinit = Math.Abs(P3.X - P1.X)
                            ps.AreaSource(ps.AreaSource.Length - 1).Xinit = Math.Abs(P3.Y - P1.Y)
                        End If
                    End If
                Else
                    P1.X = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).x
                    P1.Y = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).y
                    P20.X = Me.GetRelativelyCoordinate(pt(1).x, pt(1).y).x
                    P20.Y = Me.GetRelativelyCoordinate(pt(1).x, pt(1).y).y
                    P3.X = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).x
                    P3.Y = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).y
                    '先根据P1 P20求出斜率
                    K1 = (P20.Y - P1.Y) / (P20.X - P1.X)
                    K2 = -1 / K1
                    '再根据P1、P3反求P2和P4
                    'P2
                    Dim B1, C1, B2, C2 As Double
                    B1 = -1 * K1
                    C1 = (K1 * P1.X - P1.Y)
                    B2 = -1 * K2
                    C2 = (K2 * P3.X - P3.Y)
                    P2.Y = (B1 * C2 - B2 * C1) / (B2 - B1)
                    P2.X = (C1 - C2) / (B2 - B1)

                    'P4
                    B1 = -1 * K1
                    C1 = (K1 * P3.X - P3.Y)
                    B2 = -1 * K2
                    C2 = (K2 * P1.X - P1.Y)
                    P4.Y = (B1 * C2 - B2 * C1) / (B2 - B1)
                    P4.X = (C1 - C2) / (B2 - B1)

                    ' 按x排序所有的点，第一个点为最左边的点，最后一个点为最右边的点
                    Dim A(3) As PointF
                    A(0) = P1
                    A(1) = P2
                    A(2) = P3
                    A(3) = P4
                    For i As Integer = 0 To A.Length - 1
                        For j As Integer = i + 1 To A.Length - 1
                            If A(i).X > A(j).X Then
                                Dim PJ As PointF
                                PJ = A(i)
                                A(i) = A(j)
                                A(j) = PJ
                            End If
                        Next
                    Next
                    '再进行一次排序，对A1和A2排序，看看哪个点在上面，排A1放在上面。这样就形成一个A0，A1，A4，A2组成的长方形
                    If A(1).Y < A(2).Y Then
                        Dim Pj As PointF
                        Pj = A(1)
                        A(1) = A(2)
                        A(2) = Pj
                    End If
                    '这个长方形A0与A1的边长为Y边长，A0与A1的边长为X边长。K值即为A0与A1的边与X轴的夹角的正切值
                    Dim K As Double = (A(1).Y - A(0).Y) / (A(1).X - A(0).X)
                    '求出与X的夹角
                    AngleX = Math.Atan(K) * 180 / Math.PI
                    '求出与Y的夹角
                    AngleY = 90 - AngleX
                    '求出Y边长
                    LengY = FormatNumber(Math.Sqrt((A(1).X - A(0).X) ^ 2 + (A(1).Y - A(0).Y) ^ 2), 2)
                    '求出X边长
                    LengX = FormatNumber(Math.Sqrt((A(2).X - A(0).X) ^ 2 + (A(2).Y - A(0).Y) ^ 2), 2)

                    '设置顶点、角度和边长
                    ps.AreaSource(ps.AreaSource.Length - 1).Angle = AngleY
                    ps.AreaSource(ps.AreaSource.Length - 1).Location.Xs = FormatNumber(A(0).X, 0, TriState.True, TriState.False, TriState.False)
                    ps.AreaSource(ps.AreaSource.Length - 1).Location.Ys = FormatNumber(A(0).Y, 0, TriState.True, TriState.False, TriState.False)
                    ps.AreaSource(ps.AreaSource.Length - 1).Yinit = LengY
                    ps.AreaSource(ps.AreaSource.Length - 1).Xinit = LengX
                End If
                '调用对话框
                dlgArea.BaseSoruce = ps.AreaSource
                dlgArea.IntialSelectedIndex = dlgArea.BaseSoruce.Length - 1
                If dlgArea.ShowDialog = Windows.Forms.DialogResult.OK Then

                    '根据结果来修改方案
                    ps.AreaSource = CType(dlgArea.BaseSoruce, CAermod.AreaSource())
                    AermodProject0.Aermod.Source.AreaSources = ps.Clone
                    AermodProject0.Aermod.Source.AreaSources.nStack = dlgArea.SourceCount
                    AermodProject0.Aermod.Source.Groups.ResetGroupSource(AermodProject0.Aermod.Source) '根据用户修改的污染源修改组中的污染源
                    Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
                    myFrmMain.SolutionExplorer.RefreshSolutionTree() '根据用户的设置修改方案中的个数

                    Dim cpLayer As ESPolygonLayer
                    m_manager.GetLayer(ln, cpLayer)

                    If cpLayer IsNot Nothing Then

                        '设置第一个点
                        Dim ptA(3) As MapWinGIS.Point
                        ptA(0) = New MapWinGIS.Point
                        ptA(0).x = Me.GetUtmFromRelative(ps.AreaSource(ps.AreaSource.Length - 1).Location.Xs, ps.AreaSource(ps.AreaSource.Length - 1).Location.Ys).x
                        ptA(0).y = Me.GetUtmFromRelative(ps.AreaSource(ps.AreaSource.Length - 1).Location.Xs, ps.AreaSource(ps.AreaSource.Length - 1).Location.Ys).y
                        '设置第2个点
                        ptA(1) = New MapWinGIS.Point
                        ptA(1).y = ptA(0).y + ps.AreaSource(ps.AreaSource.Length - 1).Yinit * Math.Sin((90 - ps.AreaSource(ps.AreaSource.Length - 1).Angle) * Math.PI / 180)
                        ptA(1).x = ptA(0).x + ps.AreaSource(ps.AreaSource.Length - 1).Yinit * Math.Cos((90 - ps.AreaSource(ps.AreaSource.Length - 1).Angle) * Math.PI / 180)
                        '设置第4个点
                        ptA(3) = New MapWinGIS.Point
                        ptA(3).y = ptA(0).y + ps.AreaSource(ps.AreaSource.Length - 1).Xinit * Math.Sin(-ps.AreaSource(ps.AreaSource.Length - 1).Angle * Math.PI / 180)
                        ptA(3).x = ptA(0).x + ps.AreaSource(ps.AreaSource.Length - 1).Xinit * Math.Cos(-ps.AreaSource(ps.AreaSource.Length - 1).Angle * Math.PI / 180)

                        '设置第3个点
                        ptA(2) = New MapWinGIS.Point
                        ptA(2).y = (ptA(1).y - ptA(0).y) + ptA(3).y
                        ptA(2).x = (ptA(1).x - ptA(0).x) + ptA(3).x

                        cpLayer.AddEntity(ps.AreaSource(ps.AreaSource.Length - 1).Location.Srcid, ptA, ps.AreaSource(ps.AreaSource.Length - 1).SourceName)
                    Else
                        MessageBox.Show("未找到对应的层")

                    End If

                    '根据用户的设置修改方案中的个数
                    SetProjectSoure()
                End If

            Case "exp" '敞口源 

                Dim K1 As Double = 0 '斜率
                Dim K2 As Double = 0 '垂线的斜率
                '计算出斜率K1
                Dim P1, P20, P2, P3, P4 As PointF '用于表示4个顶点
                Dim AngleX As Double
                '求出与Y的夹角
                Dim AngleY As Double
                '求出Y边长
                Dim LengY As Double
                '求出X边长
                Dim LengX As Double
                Dim dlgOpenPit As New dlgOpenPitSource
                'dlgOpenPit.Modify()
                dlgOpenPit.Urbans = AermodProject0.Aermod.Control.Urbans
                dlgOpenPit.ArrayPollut = AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut '所有选中的污染物
                dlgOpenPit.Control = AermodProject0.Aermod.Control
                dlgOpenPit.SourceCount = AermodProject0.Aermod.Source.OpenPitSources.nStack
                '增加污染物
                Dim ps As CAermod.OpenPitSources
                ps = AermodProject0.Aermod.Source.OpenPitSources.Clone

                ReDim Preserve ps.OpenPitSource(ps.OpenPitSource.Length)
                ps.OpenPitSource(ps.OpenPitSource.Length - 1) = New CAermod.OpenPitSource
                ReDim ps.OpenPitSource(ps.OpenPitSource.Length - 1).PollutionPara(dlgOpenPit.ArrayPollut.Length - 1) '设置新增加的污染源的污染物的类型
                ps.OpenPitSource(ps.OpenPitSource.Length - 1).PollutionPara(dlgOpenPit.ArrayPollut.Length - 1) = New CAermod.PollutionPara
                ps.OpenPitSource(ps.OpenPitSource.Length - 1).SetPollutePara(AermodProject0.Aermod.Control.AllPolluts)
                ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Srcid = "OP" & (dlgOpenPit.SourceCount + 1)
                dlgOpenPit.SourceCount += 1
                '初始化污染物的名称
                ps.OpenPitSource(ps.OpenPitSource.Length - 1).SourceName = "敞口源" & dlgOpenPit.SourceCount '污染源名称
                AermodProject0.Aermod.Source.Groups.ResetGroupSource(AermodProject0.Aermod.Source) '根据用户修改的污染源修改组中的污染源


                If Math.Abs(pt(0).x - pt(1).x) < 1 Or Math.Abs(pt(0).y - pt(1).y) < 1 Then
                    '设置4个角
                    If Math.Abs(pt(0).x - pt(1).x) < 1 Then
                        P1.X = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).x
                        P1.Y = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).y
                        P3.X = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).x
                        P3.Y = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).y

                        P2.X = P1.X
                        P2.Y = P3.Y
                        P4.X = P3.X
                        P4.Y = P1.Y
                    ElseIf Math.Abs(pt(0).y - pt(1).y) < 1 Then '直角没有斜率
                        P1.X = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).x
                        P1.Y = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).y
                        P3.X = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).x
                        P3.Y = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).y
                        P2.X = P3.X
                        P2.Y = P1.Y
                        P4.X = P1.X
                        P4.Y = P3.Y
                    End If

                    '设置顶点、角度和边长
                    If P1.Y > P3.Y Then
                        If P1.X < P3.X Then
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Angle = 90
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Xs = FormatNumber(P1.X, 0, TriState.True, TriState.False, TriState.False)
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Ys = FormatNumber(P1.Y, 0, TriState.True, TriState.False, TriState.False)

                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Yinit = Math.Abs(P3.X - P1.X)
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Xinit = Math.Abs(P3.Y - P1.Y)
                        Else
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Angle = 0
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Xs = FormatNumber(P3.X, 0, TriState.True, TriState.False, TriState.False)
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Ys = FormatNumber(P3.Y, 0, TriState.True, TriState.False, TriState.False)

                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Yinit = Math.Abs(P3.Y - P1.Y)
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Xinit = Math.Abs(P3.X - P1.X)
                        End If
                    Else
                        If P1.X < P3.X Then
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Angle = 0
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Xs = FormatNumber(P1.X, 0, TriState.True, TriState.False, TriState.False)
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Ys = FormatNumber(P1.Y, 0, TriState.True, TriState.False, TriState.False)
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Yinit = Math.Abs(P3.Y - P1.Y)
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Xinit = Math.Abs(P3.X - P1.X)
                        Else
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Angle = 90
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Xs = FormatNumber(P3.X, 0, TriState.True, TriState.False, TriState.False)
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Ys = FormatNumber(P3.Y, 0, TriState.True, TriState.False, TriState.False)
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Yinit = Math.Abs(P3.X - P1.X)
                            ps.OpenPitSource(ps.OpenPitSource.Length - 1).Xinit = Math.Abs(P3.Y - P1.Y)
                        End If
                    End If
                Else
                    P1.X = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).x
                    P1.Y = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).y
                    P20.X = Me.GetRelativelyCoordinate(pt(1).x, pt(1).y).x
                    P20.Y = Me.GetRelativelyCoordinate(pt(1).x, pt(1).y).y
                    P3.X = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).x
                    P3.Y = Me.GetRelativelyCoordinate(pt(2).x, pt(2).y).y
                    '先根据P1 P20求出斜率
                    K1 = (P20.Y - P1.Y) / (P20.X - P1.X)
                    K2 = -1 / K1
                    '再根据P1、P3反求P2和P4
                    'P2
                    Dim B1, C1, B2, C2 As Double
                    B1 = -1 * K1
                    C1 = (K1 * P1.X - P1.Y)
                    B2 = -1 * K2
                    C2 = (K2 * P3.X - P3.Y)
                    P2.Y = (B1 * C2 - B2 * C1) / (B2 - B1)
                    P2.X = (C1 - C2) / (B2 - B1)

                    'P4
                    B1 = -1 * K1
                    C1 = (K1 * P3.X - P3.Y)
                    B2 = -1 * K2
                    C2 = (K2 * P1.X - P1.Y)
                    P4.Y = (B1 * C2 - B2 * C1) / (B2 - B1)
                    P4.X = (C1 - C2) / (B2 - B1)

                    ' 按x排序所有的点，第一个点为最左边的点，最后一个点为最右边的点
                    Dim A(3) As PointF
                    A(0) = P1
                    A(1) = P2
                    A(2) = P3
                    A(3) = P4
                    For i As Integer = 0 To A.Length - 1
                        For j As Integer = i + 1 To A.Length - 1
                            If A(i).X > A(j).X Then
                                Dim PJ As PointF
                                PJ = A(i)
                                A(i) = A(j)
                                A(j) = PJ
                            End If
                        Next
                    Next
                    '再进行一次排序，对A1和A2排序，看看哪个点在上面，排A1放在上面。这样就形成一个A0，A1，A4，A2组成的长方形
                    If A(1).Y < A(2).Y Then
                        Dim Pj As PointF
                        Pj = A(1)
                        A(1) = A(2)
                        A(2) = Pj
                    End If
                    '这个长方形A0与A1的边长为Y边长，A0与A1的边长为X边长。K值即为A0与A1的边与X轴的夹角的正切值
                    Dim K As Double = (A(1).Y - A(0).Y) / (A(1).X - A(0).X)
                    '求出与X的夹角
                    AngleX = Math.Atan(K) * 180 / Math.PI
                    '求出与Y的夹角
                    AngleY = 90 - AngleX
                    '求出Y边长
                    LengY = FormatNumber(Math.Sqrt((A(1).X - A(0).X) ^ 2 + (A(1).Y - A(0).Y) ^ 2), 2)
                    '求出X边长
                    LengX = FormatNumber(Math.Sqrt((A(2).X - A(0).X) ^ 2 + (A(2).Y - A(0).Y) ^ 2), 2)

                    '设置顶点、角度和边长
                    ps.OpenPitSource(ps.OpenPitSource.Length - 1).Angle = AngleY
                    ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Xs = FormatNumber(A(0).X, 0, TriState.True, TriState.False, TriState.False)
                    ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Ys = FormatNumber(A(0).Y, 0, TriState.True, TriState.False, TriState.False)
                    ps.OpenPitSource(ps.OpenPitSource.Length - 1).Yinit = LengY
                    ps.OpenPitSource(ps.OpenPitSource.Length - 1).Xinit = LengX
                End If
                '调用对话框
                dlgOpenPit.BaseSoruce = ps.OpenPitSource
                dlgOpenPit.IntialSelectedIndex = dlgOpenPit.BaseSoruce.Length - 1
                If dlgOpenPit.ShowDialog = Windows.Forms.DialogResult.OK Then

                    '根据结果来修改方案
                    ps.OpenPitSource = CType(dlgOpenPit.BaseSoruce, CAermod.OpenPitSource())
                    AermodProject0.Aermod.Source.OpenPitSources = ps.Clone
                    AermodProject0.Aermod.Source.OpenPitSources.nStack = dlgOpenPit.SourceCount
                    AermodProject0.Aermod.Source.Groups.ResetGroupSource(AermodProject0.Aermod.Source) '根据用户修改的污染源修改组中的污染源
                    Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
                    myFrmMain.SolutionExplorer.RefreshSolutionTree() '根据用户的设置修改方案中的个数

                    Dim cpLayer As ESPolygonLayer
                    m_manager.GetLayer(ln, cpLayer)

                    If cpLayer IsNot Nothing Then

                        '设置第一个点
                        Dim ptA(3) As MapWinGIS.Point
                        ptA(0) = New MapWinGIS.Point
                        ptA(0).x = Me.GetUtmFromRelative(ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Xs, ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Ys).x
                        ptA(0).y = Me.GetUtmFromRelative(ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Xs, ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Ys).y
                        '设置第2个点
                        ptA(1) = New MapWinGIS.Point
                        ptA(1).y = ptA(0).y + ps.OpenPitSource(ps.OpenPitSource.Length - 1).Yinit * Math.Sin((90 - ps.OpenPitSource(ps.OpenPitSource.Length - 1).Angle) * Math.PI / 180)
                        ptA(1).x = ptA(0).x + ps.OpenPitSource(ps.OpenPitSource.Length - 1).Yinit * Math.Cos((90 - ps.OpenPitSource(ps.OpenPitSource.Length - 1).Angle) * Math.PI / 180)
                        '设置第4个点
                        ptA(3) = New MapWinGIS.Point
                        ptA(3).y = ptA(0).y + ps.OpenPitSource(ps.OpenPitSource.Length - 1).Xinit * Math.Sin(-ps.OpenPitSource(ps.OpenPitSource.Length - 1).Angle * Math.PI / 180)
                        ptA(3).x = ptA(0).x + ps.OpenPitSource(ps.OpenPitSource.Length - 1).Xinit * Math.Cos(-ps.OpenPitSource(ps.OpenPitSource.Length - 1).Angle * Math.PI / 180)

                        '设置第3个点
                        ptA(2) = New MapWinGIS.Point
                        ptA(2).y = (ptA(1).y - ptA(0).y) + ptA(3).y
                        ptA(2).x = (ptA(1).x - ptA(0).x) + ptA(3).x

                        cpLayer.AddEntity(ps.OpenPitSource(ps.OpenPitSource.Length - 1).Location.Srcid, ptA, ps.OpenPitSource(ps.OpenPitSource.Length - 1).SourceName)
                    Else
                        MessageBox.Show("未找到对应的层")

                    End If

                    '根据用户的设置修改方案中的个数
                    SetProjectSoure()
                End If

            Case "build" '建筑物 
                Dim frmbp As New CAermod.frmSingleBuilding
                frmbp.Bldgi.BuildName = "建筑物" & AermodProject0.Aermod.Bprm.No + 1


                '设置第一个顶点坐标
                Dim P As PointF
                P.X = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).x
                P.Y = Me.GetRelativelyCoordinate(pt(0).x, pt(0).y).y
                '设置其它顶点

                Dim AF(pt.Length - 1) As PointF
                Dim AP(pt.Length - 1) As Point
                ReDim frmbp.Bldgi.ArryBuildTire(0).ArryBuilCorner(AF.Length - 1)
                For i As Integer = 0 To AF.Length - 1
                    AF(i).X = Me.GetRelativelyCoordinate(pt(i).x, pt(i).y).x
                    AF(i).Y = Me.GetRelativelyCoordinate(pt(i).x, pt(i).y).y

                    AP(i).X = AF(i).X
                    AP(i).Y = AF(i).Y
                    frmbp.Bldgi.ArryBuildTire(0).ArryBuilCorner(i) = New CAermod.BuildCorner
                    frmbp.Bldgi.ArryBuildTire(0).ArryBuilCorner(i).x = AP(i).X
                    frmbp.Bldgi.ArryBuildTire(0).ArryBuilCorner(i).y = AP(i).Y
                Next

                If frmbp.ShowDialog = Windows.Forms.DialogResult.OK Then

                    ReDim Preserve AermodProject0.Aermod.Bprm.ArryBldgi(AermodProject0.Aermod.Bprm.ArryBldgi.Length)
                    AermodProject0.Aermod.Bprm.ArryBldgi(AermodProject0.Aermod.Bprm.ArryBldgi.Length - 1) = frmbp.Bldgi
                    AermodProject0.Aermod.Bprm.ArryBldgi(AermodProject0.Aermod.Bprm.ArryBldgi.Length - 1).BuildStack = "Bpip" & AermodProject0.Aermod.Bprm.No + 1
                    AermodProject0.Aermod.Bprm.No += 1
                    AermodProject0.Aermod.Source.Groups.ResetGroupSource(AermodProject0.Aermod.Source) '根据用户修改的污染源修改组中的污染源
                    Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
                    myFrmMain.SolutionExplorer.RefreshSolutionTree() '根据用户的设置修改方案中的个数



                    Dim cpLayer As ESPolygonLayer
                    m_manager.GetLayer(ln, cpLayer)

                    Dim BldgiTemp As CAermod.Bldgi = AermodProject0.Aermod.Bprm.ArryBldgi(AermodProject0.Aermod.Bprm.ArryBldgi.Length - 1)
                    If cpLayer IsNot Nothing Then

                        '设置第一个点
                        Dim ptA(BldgiTemp.ArryBuildTire(0).ArryBuilCorner.Length - 1) As MapWinGIS.Point
                        For i As Integer = 0 To BldgiTemp.ArryBuildTire(0).ArryBuilCorner.Length - 1
                            ptA(i) = New MapWinGIS.Point
                            ptA(i).x = Me.GetUtmFromRelative(BldgiTemp.ArryBuildTire(0).ArryBuilCorner(i).x, BldgiTemp.ArryBuildTire(0).ArryBuilCorner(i).y).x
                            ptA(i).y = Me.GetUtmFromRelative(BldgiTemp.ArryBuildTire(0).ArryBuilCorner(i).x, BldgiTemp.ArryBuildTire(0).ArryBuilCorner(i).y).y

                        Next
                        cpLayer.AddEntity(BldgiTemp.BuildStack, ptA, BldgiTemp.BuildName)
                    Else
                        MessageBox.Show("未找到对应的层")

                    End If
                    '根据用户的设置修改方案中的个数
                    SetProjectSoure()
                End If
        End Select
    End Sub
    '''' <summary>
    '''' 删除污染源或关心点
    '''' </summary>
    '''' <param name="ln"></param>
    '''' <param name="sn"></param>
    '''' <remarks></remarks>
    'Private Sub OnAskRemove(ByVal ln As String, ByVal sn As String)


    '    Dim cpLayer As EditableShapeLayer
    '    m_manager.GetLayer(ln, cpLayer)
    '    If cpLayer IsNot Nothing Then
    '        Select Case ln
    '            Case "ppoint", "pline", "pline", "poly", "cube", "circle", "rect", "exp"
    '                AermodProject0.Aermod.Source.RemoveFormID(sn)
    '            Case "cpoint" '关心点
    '                AermodProject0.Aermod.Receptor.RemoveDiscFormID(sn)
    '            Case "build" '建筑物
    '                AermodProject0.Aermod.Bprm.RemoveFormID(sn)
    '        End Select
    '        cpLayer.RemoveEntity(sn)
    '    End If
    '    Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
    '    myFrmMain.SolutionExplorer.RefreshSolutionTree()
    'End Sub

    Private Sub OnSelected(ByVal ln As String, ByVal sn As String)

        ' MessageBox.Show(sn)

    End Sub

    ''' <summary>
    ''' 根据主网格返回相对坐标
    ''' </summary>
    ''' <param name="UtmX">绝对坐标X</param>
    ''' <param name="UtmY">绝对坐标Y</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetRelativelyCoordinate(ByVal UtmX As Double, ByVal UtmY As Double) As GisMapF.Point3D
        Return Me.Assistant.GetRelativelyCoordinate(UtmX, UtmY, "grid", "axis")
    End Function
    ''' <summary>
    ''' 根据相对坐标求得绝对坐标
    ''' </summary>
    ''' <param name="x">相对坐标X</param>
    ''' <param name="y">相对坐标Y</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetUtmFromRelative(ByVal x As Double, ByVal y As Double) As GisMapF.Point3D
        Return Assistant.GetUtmFromRelative(x, y, "grid", "axis")
    End Function

    Public Sub Remove(ByVal ln As String)
        Dim cpLayer As EditableShapeLayer
        m_manager.GetLayer(ln, cpLayer)
        cpLayer.RemoveAllEntity()
    End Sub
    ''' <summary>
    ''' 移除
    ''' </summary>
    ''' <param name="ln"></param>
    ''' <param name="sn"></param>
    ''' <remarks></remarks>
    Private Sub OnAskRemove(ByVal ln As String, ByVal sn As String)
        Dim cpLayer As EditableShapeLayer
        m_manager.GetLayer(ln, cpLayer)
        If cpLayer IsNot Nothing Then
            Select Case ln
                Case "cpoint" '关心点
                    For i As Integer = 0 To AermodProject0.Aermod.Receptor.DiscCarts.Length - 1
                        If sn = AermodProject0.Aermod.Receptor.DiscCarts(i).ID Then
                            '
                            AermodProject0.Aermod.BackCon.PolluteChaged(AermodProject0.Aermod.Control.AllPolluts, AermodProject0.Aermod.Receptor.DiscCarts)
                            '
                            For j As Integer = i To AermodProject0.Aermod.Receptor.DiscCarts.Length - 2
                                AermodProject0.Aermod.Receptor.DiscCarts(j) = AermodProject0.Aermod.Receptor.DiscCarts(j + 1)
                            Next
                            ReDim Preserve AermodProject0.Aermod.Receptor.DiscCarts(AermodProject0.Aermod.Receptor.DiscCarts.Length - 2)
                            Exit For

                        End If
                    Next
                Case "ppoint" '点源
                    For i As Integer = 0 To AermodProject0.Aermod.Source.PointSources.PointSource.Length - 1
                        If sn = AermodProject0.Aermod.Source.PointSources.PointSource(i).Location.Srcid Then

                            For j As Integer = i To AermodProject0.Aermod.Source.PointSources.PointSource.Length - 2
                                AermodProject0.Aermod.Source.PointSources.PointSource(j) = AermodProject0.Aermod.Source.PointSources.PointSource(j + 1)
                            Next
                            ReDim Preserve AermodProject0.Aermod.Source.PointSources.PointSource(AermodProject0.Aermod.Source.PointSources.PointSource.Length - 2)
                            Exit For
                        End If
                    Next
                Case "pline" '线源
                    For i As Integer = 0 To AermodProject0.Aermod.Source.LineSources.ArrayLineSources.Length - 1
                        If sn = AermodProject0.Aermod.Source.LineSources.ArrayLineSources(i).Location.Srcid Then

                            For j As Integer = i To AermodProject0.Aermod.Source.LineSources.ArrayLineSources.Length - 2
                                AermodProject0.Aermod.Source.LineSources.ArrayLineSources(j) = AermodProject0.Aermod.Source.LineSources.ArrayLineSources(j + 1)
                            Next
                            ReDim Preserve AermodProject0.Aermod.Source.LineSources.ArrayLineSources(AermodProject0.Aermod.Source.LineSources.ArrayLineSources.Length - 2)
                            Exit For
                        End If
                    Next
                Case "poly" '多边形
                    For i As Integer = 0 To AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource.Length - 1
                        If sn = AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(i).Location.Srcid Then

                            For j As Integer = i To AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource.Length - 2
                                AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j) = AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(j + 1)
                            Next
                            ReDim Preserve AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource.Length - 2)
                            Exit For
                        End If
                    Next
                Case "cube" '体源
                    For i As Integer = 0 To AermodProject0.Aermod.Source.VolumeSources.VolumeSource.Length - 1
                        If sn = AermodProject0.Aermod.Source.VolumeSources.VolumeSource(i).Location.Srcid Then

                            For j As Integer = i To AermodProject0.Aermod.Source.VolumeSources.VolumeSource.Length - 2
                                AermodProject0.Aermod.Source.VolumeSources.VolumeSource(j) = AermodProject0.Aermod.Source.VolumeSources.VolumeSource(j + 1)
                            Next
                            ReDim Preserve AermodProject0.Aermod.Source.VolumeSources.VolumeSource(AermodProject0.Aermod.Source.VolumeSources.VolumeSource.Length - 2)
                            Exit For
                        End If
                    Next
                Case "circle" '圆形面源
                    For i As Integer = 0 To AermodProject0.Aermod.Source.AreacircSources.AreaCircSource.Length - 1
                        If sn = AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(i).Location.Srcid Then

                            For j As Integer = i To AermodProject0.Aermod.Source.AreacircSources.AreaCircSource.Length - 2
                                AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(j) = AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(j + 1)
                            Next
                            ReDim Preserve AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(AermodProject0.Aermod.Source.AreacircSources.AreaCircSource.Length - 2)
                            Exit For
                        End If
                    Next
                Case "rect" '矩形面源
                    For i As Integer = 0 To AermodProject0.Aermod.Source.AreaSources.AreaSource.Length - 1
                        If sn = AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Location.Srcid Then

                            For j As Integer = i To AermodProject0.Aermod.Source.AreaSources.AreaSource.Length - 2
                                AermodProject0.Aermod.Source.AreaSources.AreaSource(j) = AermodProject0.Aermod.Source.AreaSources.AreaSource(j + 1)
                            Next
                            ReDim Preserve AermodProject0.Aermod.Source.AreaSources.AreaSource(AermodProject0.Aermod.Source.AreaSources.AreaSource.Length - 2)
                            Exit For
                        End If
                    Next
                Case "exp" '敞口源
                    For i As Integer = 0 To AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource.Length - 1
                        If sn = AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Location.Srcid Then

                            For j As Integer = i To AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource.Length - 2
                                AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(j) = AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(j + 1)
                            Next
                            ReDim Preserve AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource.Length - 2)
                            Exit For
                        End If
                    Next
                Case "build" '建筑物
                    For i As Integer = 0 To AermodProject0.Aermod.Bprm.ArryBldgi.Length - 1
                        If sn = AermodProject0.Aermod.Bprm.ArryBldgi(i).BuildStack Then

                            For j As Integer = i To AermodProject0.Aermod.Bprm.ArryBldgi.Length - 2
                                AermodProject0.Aermod.Bprm.ArryBldgi(j) = AermodProject0.Aermod.Bprm.ArryBldgi(j + 1)
                            Next
                            ReDim Preserve AermodProject0.Aermod.Bprm.ArryBldgi(AermodProject0.Aermod.Bprm.ArryBldgi.Length - 2)
                            Exit For
                        End If
                    Next
            End Select
            Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
            myFrmMain.SolutionExplorer.RefreshSolutionTree() '根据用户的设置修改方案中的个数
            '根据用户的设置修改方案中的个数
            SetProjectSoure()
            '根据关心点更新方案
            SetProjectReceptor()
        End If
        cpLayer.RemoveEntity(sn)
    End Sub
    ''' <summary>
    ''' 更新污染源、关心点、建筑物等数据
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub UpWholeAllSource()
        Me.UpAllSource("cpoint")
        Me.UpAllSource("ppoint")
        Me.UpAllSource("pline")
        Me.UpAllSource("poly")
        Me.UpAllSource("cube")
        Me.UpAllSource("circle")
        Me.UpAllSource("rect")
        Me.UpAllSource("exp")
        Me.UpAllSource("build")

    End Sub
    Public Sub UpAllSource(ByVal ln As String)
        Dim list_1 As New List(Of GisMapF.FEntity)
        Dim cpLayer As EditableShapeLayer

        Select Case ln
            Case "cpoint" '关心点
                Me.Remove("cpoint") '删除所有图层
                m_manager.GetLayer("cpoint", cpLayer)
                For i As Integer = 0 To AermodProject0.Aermod.Receptor.DiscCarts.Length - 1

                    Dim fe As New GisMapF.FEntity
                    fe.desc = AermodProject0.Aermod.Receptor.DiscCarts(i).Name
                    fe.sn = AermodProject0.Aermod.Receptor.DiscCarts(i).ID
                    ReDim fe.ptlist(0)
                    fe.ptlist(0) = New MapWinGIS.Point
                    AermodProject0.Aermod.Receptor.DiscCarts(i).Xcoord = FormatNumber(AermodProject0.Aermod.Receptor.DiscCarts(i).Xcoord, 2, TriState.True, TriState.False, TriState.False)
                    AermodProject0.Aermod.Receptor.DiscCarts(i).Ycoord = FormatNumber(AermodProject0.Aermod.Receptor.DiscCarts(i).Ycoord, 2, TriState.True, TriState.False, TriState.False)
                    fe.ptlist(0).x = AermodProject0.GetOffsetX + AermodProject0.Aermod.Receptor.DiscCarts(i).Xcoord
                    fe.ptlist(0).y = AermodProject0.GetOffsetY + AermodProject0.Aermod.Receptor.DiscCarts(i).Ycoord

                    list_1.Add(fe)
                Next

                CType(cpLayer, GisMapF.ESPointLayer).AddEntityRange(list_1)

            Case "ppoint"

                Me.Remove("ppoint") '删除所有图层
                m_manager.GetLayer("ppoint", cpLayer)
                For i As Integer = 0 To AermodProject0.Aermod.Source.PointSources.PointSource.Length - 1
                    Dim fe As New GisMapF.FEntity
                    fe.desc = AermodProject0.Aermod.Source.PointSources.PointSource(i).SourceName
                    fe.sn = AermodProject0.Aermod.Source.PointSources.PointSource(i).Location.Srcid
                    ReDim fe.ptlist(0)
                    fe.ptlist(0) = New MapWinGIS.Point
                    AermodProject0.Aermod.Source.PointSources.PointSource(i).Location.Xs = FormatNumber(AermodProject0.Aermod.Source.PointSources.PointSource(i).Location.Xs, 2, TriState.True, TriState.False, TriState.False)
                    AermodProject0.Aermod.Source.PointSources.PointSource(i).Location.Ys = FormatNumber(AermodProject0.Aermod.Source.PointSources.PointSource(i).Location.Ys, 2, TriState.True, TriState.False, TriState.False)

                    fe.ptlist(0).x = AermodProject0.GetOffsetX + AermodProject0.Aermod.Source.PointSources.PointSource(i).Location.Xs
                    fe.ptlist(0).y = AermodProject0.GetOffsetY + AermodProject0.Aermod.Source.PointSources.PointSource(i).Location.Ys

                    list_1.Add(fe)

                Next

                CType(cpLayer, GisMapF.ESPointLayer).AddEntityRange(list_1)

            Case "pline" '线源
                Me.Remove("pline") '删除所有图层
                m_manager.GetLayer("pline", cpLayer)

                For i As Integer = 0 To AermodProject0.Aermod.Source.LineSources.ArrayLineSources.Length - 1

                    Dim fe As New GisMapF.FEntity
                    Dim p As Integer = 0
                    ReDim fe.ptlist(0)

                    fe.desc = AermodProject0.Aermod.Source.LineSources.ArrayLineSources(i).SourceName
                    fe.sn = AermodProject0.Aermod.Source.LineSources.ArrayLineSources(i).Location.Srcid
                    For j As Integer = 0 To AermodProject0.Aermod.Source.LineSources.ArrayLineSources(i).LinePoints.Length - 1


                        ReDim Preserve fe.ptlist(p)
                        fe.ptlist(p) = New MapWinGIS.Point

                        fe.ptlist(p).x = AermodProject0.GetOffsetX + AermodProject0.Aermod.Source.LineSources.ArrayLineSources(i).LinePoints(j).x
                        fe.ptlist(p).y = AermodProject0.GetOffsetY + AermodProject0.Aermod.Source.LineSources.ArrayLineSources(i).LinePoints(j).y

                        p += 1

                    Next
                    list_1.Add(fe)
                Next

                CType(cpLayer, GisMapF.ESMLineLayer).AddEntityRange(list_1)

            Case "poly" '多边形

                Me.Remove("poly") '删除所有图层
                m_manager.GetLayer("poly", cpLayer)

                For i As Integer = 0 To AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource.Length - 1

                    Dim fe As New GisMapF.FEntity
                    Dim p As Integer = 0
                    ReDim fe.ptlist(0)

                    fe.desc = AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(i).SourceName
                    fe.sn = AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(i).Location.Srcid

                    fe.ptlist(0) = New MapWinGIS.Point
                    fe.ptlist(0).x = AermodProject0.GetOffsetX + AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(i).Location.Xs
                    fe.ptlist(0).y = AermodProject0.GetOffsetY + AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(i).Location.Ys

                    For j As Integer = 0 To AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(i).GetVerts.Length - 1


                        ReDim Preserve fe.ptlist(p + 1)
                        fe.ptlist(p + 1) = New MapWinGIS.Point

                        fe.ptlist(p + 1).x = AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(i).GetVerts(j).X + AermodProject0.GetOffsetX
                        fe.ptlist(p + 1).y = AermodProject0.Aermod.Source.AreaPolySources.AreaPolySource(i).GetVerts(j).Y + AermodProject0.GetOffsetY

                        p += 1

                    Next
                    list_1.Add(fe)
                Next
                CType(cpLayer, GisMapF.ESPolygonLayer).AddEntityRange(list_1)
            Case "cube" '体源
                Me.Remove("cube") '删除所有图层
                m_manager.GetLayer("cube", cpLayer)

                For i As Integer = 0 To AermodProject0.Aermod.Source.VolumeSources.VolumeSource.Length - 1

                    Dim fe As New GisMapF.FEntity
                    Dim ps As CAermod.VolumeSources
                    ps = AermodProject0.Aermod.Source.VolumeSources
                    Dim p As Integer = 0
                    ReDim fe.ptlist(0)

                    fe.desc = AermodProject0.Aermod.Source.VolumeSources.VolumeSource(i).SourceName
                    fe.sn = AermodProject0.Aermod.Source.VolumeSources.VolumeSource(i).Location.Srcid
                    Dim ptA(3) As MapWinGIS.Point
                    ptA(0) = New MapWinGIS.Point
                    ptA(0).x = ps.VolumeSource(i).Location.Xs - ps.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetX
                    ptA(0).y = ps.VolumeSource(i).Location.Ys - ps.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetY

                    ptA(1) = New MapWinGIS.Point
                    ptA(1).x = ps.VolumeSource(i).Location.Xs - ps.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetX
                    ptA(1).y = ps.VolumeSource(i).Location.Ys + ps.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetY

                    ptA(2) = New MapWinGIS.Point
                    ptA(2).x = ps.VolumeSource(i).Location.Xs + ps.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetX
                    ptA(2).y = ps.VolumeSource(i).Location.Ys + ps.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetY

                    ptA(3) = New MapWinGIS.Point
                    ptA(3).x = ps.VolumeSource(i).Location.Xs + ps.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetX
                    ptA(3).y = ps.VolumeSource(i).Location.Ys - ps.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetY

                    ReDim Preserve fe.ptlist(ptA.Length - 1)
                    For j As Integer = 0 To ptA.Length - 1
                        fe.ptlist(p) = New MapWinGIS.Point
                        fe.ptlist(p).x = ptA(j).x
                        fe.ptlist(p).y = ptA(j).y
                        p += 1
                    Next
                    list_1.Add(fe)

                Next

                CType(cpLayer, GisMapF.ESPolygonLayer).AddEntityRange(list_1)

            Case "circle" '圆形面源

                Me.Remove("circle") '删除所有图层
                m_manager.GetLayer("circle", cpLayer)
                For i As Integer = 0 To AermodProject0.Aermod.Source.AreacircSources.AreaCircSource.Length - 1

                    Dim fe As New GisMapF.FEntity
                    Dim p As Integer = 0

                    fe.desc = AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(i).SourceName
                    fe.sn = AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(i).Location.Srcid
                    Dim ptA As MapWinGIS.Point
                    ptA = New MapWinGIS.Point
                    ptA.x = AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(i).Location.Xs + AermodProject0.GetOffsetX
                    ptA.y = AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(i).Location.Ys + AermodProject0.GetOffsetY



                    Dim r As Double = AermodProject0.Aermod.Source.AreacircSources.AreaCircSource(i).Radius
                    Dim ptReturn As New List(Of MapWinGIS.Point)

                    For j As Double = 0 To 2 * Math.PI Step Math.PI / 360
                        Dim pTemp As New MapWinGIS.Point
                        pTemp.x = r * Math.Cos(j) + ptA.x
                        pTemp.y = r * Math.Sin(j) + ptA.y
                        ptReturn.Add(pTemp)
                    Next
                    fe.ptlist = ptReturn.ToArray
                    list_1.Add(fe)
                Next
                CType(cpLayer, GisMapF.ESPolygonLayer).AddEntityRange(list_1)
            Case "rect" '矩形面源
                Me.Remove("rect") '删除所有图层
                m_manager.GetLayer("rect", cpLayer)

                For i As Integer = 0 To AermodProject0.Aermod.Source.AreaSources.AreaSource.Length - 1

                    Dim fe As New GisMapF.FEntity
                    Dim p As Integer = 0
                    ReDim fe.ptlist(0)

                    fe.desc = AermodProject0.Aermod.Source.AreaSources.AreaSource(i).SourceName
                    fe.sn = AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Location.Srcid

                    '设置第一个点
                    Dim ptA(3) As MapWinGIS.Point
                    ptA(0) = New MapWinGIS.Point
                    ptA(0).x = AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Location.Xs + AermodProject0.GetOffsetX
                    ptA(0).y = AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Location.Ys + AermodProject0.GetOffsetY
                    '设置第2个点
                    ptA(1) = New MapWinGIS.Point
                    ptA(1).y = ptA(0).y + AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Yinit * Math.Sin((90 - AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Angle) * Math.PI / 180)
                    ptA(1).x = ptA(0).x + AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Yinit * Math.Cos((90 - AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Angle) * Math.PI / 180)
                    '设置第4个点
                    ptA(3) = New MapWinGIS.Point
                    ptA(3).y = ptA(0).y + AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Xinit * Math.Sin(-AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Angle * Math.PI / 180)
                    ptA(3).x = ptA(0).x + AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Xinit * Math.Cos(-AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Angle * Math.PI / 180)

                    '设置第3个点
                    ptA(2) = New MapWinGIS.Point
                    ptA(2).y = (ptA(1).y - ptA(0).y) + ptA(3).y
                    ptA(2).x = (ptA(1).x - ptA(0).x) + ptA(3).x
                    fe.ptlist = ptA
                    list_1.Add(fe)
                Next
                CType(cpLayer, GisMapF.ESPolygonLayer).AddEntityRange(list_1)
            Case "exp" '敞口源

                Me.Remove("exp") '删除所有图层
                m_manager.GetLayer("exp", cpLayer)

                For i As Integer = 0 To AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource.Length - 1

                    Dim fe As New GisMapF.FEntity
                    Dim p As Integer = 0
                    ReDim fe.ptlist(0)

                    fe.desc = AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).SourceName
                    fe.sn = AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Location.Srcid
                    '设置第一个点
                    Dim ptA(3) As MapWinGIS.Point
                    ptA(0) = New MapWinGIS.Point
                    ptA(0).x = AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Location.Xs + AermodProject0.GetOffsetX
                    ptA(0).y = AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Location.Ys + AermodProject0.GetOffsetY
                    '设置第2个点
                    ptA(1) = New MapWinGIS.Point
                    ptA(1).y = ptA(0).y + AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Yinit * Math.Sin((90 - AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Angle) * Math.PI / 180)
                    ptA(1).x = ptA(0).x + AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Yinit * Math.Cos((90 - AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Angle) * Math.PI / 180)
                    '设置第4个点
                    ptA(3) = New MapWinGIS.Point
                    ptA(3).y = ptA(0).y + AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Xinit * Math.Sin(-AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Angle * Math.PI / 180)
                    ptA(3).x = ptA(0).x + AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Xinit * Math.Cos(-AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Angle * Math.PI / 180)

                    '设置第3个点
                    ptA(2) = New MapWinGIS.Point
                    ptA(2).y = (ptA(1).y - ptA(0).y) + ptA(3).y
                    ptA(2).x = (ptA(1).x - ptA(0).x) + ptA(3).x

                    fe.ptlist = ptA
                    list_1.Add(fe)
                Next
                CType(cpLayer, GisMapF.ESPolygonLayer).AddEntityRange(list_1)
            Case "build" '建筑物

                Me.Remove("build") '删除所有图层
                m_manager.GetLayer("build", cpLayer)

                For i As Integer = 0 To AermodProject0.Aermod.Bprm.ArryBldgi.Length - 1

                    Dim fe As New GisMapF.FEntity
                    Dim p As Integer = 0
                    ReDim fe.ptlist(0)

                    fe.desc = AermodProject0.Aermod.Bprm.ArryBldgi(i).BuildName
                    fe.sn = AermodProject0.Aermod.Bprm.ArryBldgi(i).BuildStack
                    '设置第一个点
                    Dim ptA(AermodProject0.Aermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner.Length - 1) As MapWinGIS.Point
                    For j As Integer = 0 To AermodProject0.Aermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner.Length - 1
                        ptA(j) = New MapWinGIS.Point
                        ptA(j).x = AermodProject0.Aermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).x + AermodProject0.GetOffsetX
                        ptA(j).y = AermodProject0.Aermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).y + AermodProject0.GetOffsetY

                    Next


                    fe.ptlist = ptA
                    list_1.Add(fe)
                Next
                CType(cpLayer, GisMapF.ESPolygonLayer).AddEntityRange(list_1)
        End Select

        Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
        myFrmMain.SolutionExplorer.RefreshSolutionTree()

    End Sub
    Public Sub Add(ByVal ln As String, ByVal Id As String, ByVal Points As Point3D(), ByVal Name As String)
        Dim cpLayer As EditableShapeLayer
        m_manager.GetLayer(ln, cpLayer)
        If cpLayer IsNot Nothing Then
            Select Case ln
                Case "cpoint" '关心点
                    If cpLayer IsNot Nothing Then

                        Dim ptA(0) As MapWinGIS.Point
                        ptA(0) = New MapWinGIS.Point
                        ptA(0).x = Me.GetUtmFromRelative(Points(0).x, Points(0).y).x
                        ptA(0).y = Me.GetUtmFromRelative(Points(0).x, Points(0).y).y
                        cpLayer.AddEntity(Id, ptA, Name)
                    Else
                        MessageBox.Show("未找到对应的层")

                    End If
                Case "ppoint"
                    If cpLayer IsNot Nothing Then

                        Dim ptA(0) As MapWinGIS.Point
                        ptA(0) = New MapWinGIS.Point
                        ptA(0).x = Me.GetUtmFromRelative(Points(0).x, Points(0).y).x
                        ptA(0).y = Me.GetUtmFromRelative(Points(0).x, Points(0).y).y
                        cpLayer.AddEntity(Id, ptA, Name)
                    Else
                        MessageBox.Show("未找到对应的层")

                    End If
                Case "pline" '增加线源
                Case "poly" '多边形
                Case "cube" '体源
                Case "circle" '圆形面源
                Case "rect" '矩形面源
                Case "exp" '敞口源
                Case "build" '建筑物
            End Select
        End If
        Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
        myFrmMain.SolutionExplorer.RefreshSolutionTree()
    End Sub

    ''' <summary>
    ''' 鼠标移动，显示坐标
    ''' </summary>
    ''' <param name="x"></param>
    ''' <param name="y"></param>
    ''' <remarks></remarks>
    Private Sub OnMousePosChanged(ByVal x As Double, ByVal y As Double)
        Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
        myFrmMain.txtLocation.Text = "UTM:" & FormatNumber(x, 2, TriState.True, TriState.False, TriState.False) & "," & FormatNumber(y, 2, TriState.True, TriState.False, TriState.False)
        myFrmMain.txtXYLocation.Text = "相对坐标:" & FormatNumber(x - AermodProject0.GetOffsetX, 2, TriState.True, TriState.False, TriState.False) & " , " & FormatNumber(y - AermodProject0.GetOffsetY, 2, TriState.True, TriState.False, TriState.False)

    End Sub

    ''' <summary>
    ''' 向图层中添加DEM数据
    ''' </summary>
    ''' <param name="FileName">DEM数据文件的名称，包含路径</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function AddDemMap(ByVal FileName As String) As Boolean
        Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
        Me.Assistant.AddTif(FileName, frmMain.m_tree)
    End Function
    Private Sub AxMap1_MouseDownEvent(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_MouseDownEvent) Handles AxMap1.MouseDownEvent
        If e.button = 2 Then
            Dim m_dic As Dictionary(Of String, String)
            m_dic = m_manager.GetSelectedShapeNamesWithLayerName()
            If m_dic.Count > 0 Then
                Me.ContextMenuStrip = Me.ContextMenuStrip1
            Else
                Me.ContextMenuStrip = Nothing

            End If
        End If
    End Sub
    Private Sub 移动ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 移动ToolStripMenuItem.Click
        Me.m_manager.UseMoveTool(True, Cursors.Cross)
    End Sub

    Private Sub 编辑ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 编辑ToolStripMenuItem.Click
        Me.SetBluepencil()
    End Sub
    Private Sub 删除ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 删除ToolStripMenuItem.Click
        Dim m_dic As Dictionary(Of String, String)
        m_dic = m_manager.GetSelectedShapeNamesWithLayerName()
        For Each d As KeyValuePair(Of String, String) In m_dic
            OnAskRemove(d.Value, d.Key)
        Next
    End Sub
End Class
